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:
[Settings] Priority=Default [Default] OSInstall=Y OSDComputerName=#TrimSerial("%SerialNumber%")# UserExit=Z-TrimSerialNum.wsf
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.