Implementing UserExit Scripts

UserExit scripts can be a very useful way of interacting with the rule validation process in MDT and provides dynamic updates of properties in MDT.

I have recently been working with a customer who had a requirement to trim the Serial Number of some of their systems because of external dependencies in other applications. It’s really easy to setup and get working and you can extend MDT quite a bit and provide some great functionality.

First of all create a new WSF file in the Scripts folder of your Deployment Share, once you have created the file, in our example Z-TrimSerialNum.wsf the file needs to be referenced in CustomSettings.ini where it will be called and the processing will take place. Here is our CustomSettings.ini file:


So let’s have a look at what is happening. What we are doing here it to say we have our %SerialNumber% variable which comes from the machine we are building. We are going to set the value of OSDComputerName to be the value of %SerialNumber% however before we do that the hashes here say we want to run a user exit script. On the line below we define the name of this script in the UserExit= line.

Once that is done, here is the contents of our script:

Function UserExit(sType, sWhen, sDetail, bSkip)
   UserExit = Success
End Function
Function TrimSerial(vSerial)
   oLogging.CreateEntry "UserExit - Trimming Serial Number"
  oLogging.CreateEntry "Trimmed Serial: " & Left(vSerial, 8)
  TrimSerial = Left(vSerial, 8)
End Function

This is pretty basic scripting but all you are doing here is setting the name of the function to return the value you want. The little function above is just what you need to include at the top to make this all work.

So as you can see, simple and easy to set up, quite a lot of power at your finger tips as well which extends MDT yet more. It actually took me longer to write this post than it did to implement the above.


Tags: , , , ,

About Martyn

Martyn is one of the Senior Cloud Architects and DevOps Team Leader at one of the worlds leading Cloud Transformation Specialists Inframon. Martyn is responsible for the architecture of some of the largest Azure deployments in EMEA and is a advisor to a many businesses on their strategies. Martyn is a regular speaker at Microsoft events and community events on Azure and DevOps, giving his insight to a growing number of audiences.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: