Microsoft Deployment Toolkit (MDT)–User Exit Scripts | Quisitive
Microsoft Deployment Toolkit (MDT)–User Exit Scripts
November 2, 2010
Quisitive
Today we'll look at Microsoft Deployment Toolkit

Today we’ll look at Microsoft Deployment Toolkit and its user exit scripts, but first some examples:

MDT Documentation Example

It also is possible to run the custom code as a user exit script from CustomSettings.ini.

This provides a mechanism for information to be passed into the CustomSettings.ini rule validation process and provides a dynamic update of MDT 2010 properties.

A user exit script is effectively a function library that can be called during the processing of CustomSettings.ini:

·         A user exit script will contain one or more functions that can be called during CustomSettings.ini processing.

·         The user exit script is called by specifying the UserExit property and assigning the property name of the script to be called; for example, UserExit=TrimAssetTag.vbs.

·         A function is called by specifying the name of a function enclosed in the # characters. For example, if the user exit script contains a function called TrimAssetTag(), it would be called by specifying #TrimAssetTag()#.

·         Parameters can be passed to the function in the usual way by specifying the parameter while calling the function. For example, to pass the variable %ASSETTAG% to the function TrimAssetTag(), the function would be called by specifying #TrimAssetTag(“%ASSETTAG%”)#.

·         The value returned by the function can be assigned to a variable by assigning the function to that variable. For example, to take the asset tag of a computer and trim it using the function TrimAssetTag(), and to then reassign the trimmed asset tag to the variable AssetTag, the CustomSettings.ini file would read AssetTag=#TrimAssetTag(“%ASSETTAG%”)#.

An example of how this could be used is to determine the task sequence to be run based on a rule that sets the TaskSequenceID property.

Listing 26 is an example user exit script that determines the task sequence to be run based on the amount of available RAM. This script also uses the ZTIUtility logging class.

Listing 26. Example User Exit Script

Function UserExit(sType, sWhen, sDetail, bSkip)

  UserExit = Success

End Function

Function SetTaskSequence(vMemory)

  oLogging.CreateEntry “UserExit – Determining Task ” & _

    “Sequence to run based on available RAM”, LogTypeInfo

  If vMemory <= 2048 Then

    SetTaskSequence = “XP_X86”

    oLogging.CreateEntry “UserExit – Available RAM: ” & _

      vMemory & “. Selecting XP_X86 TS.”, LogTypeInfo

  Else

    SetTaskSequence = “Vista_X86”

    oLogging.CreateEntry “UserExit – Available RAM: ” & _

      vMemory & “. Selecting Vista_X86 TS.”, LogTypeInfo

  End If

End Function

The user exit script should be placed in the Scripts folder on the deployment share (for example, D:\Production Deployment Share\Scripts).

To create the user exit script

1.   Create and test the custom script to be used.

2.   Locate the MDT 2010 Scripts folder (for example, D:\Production Deployment Share\Scripts).

3.   Copy the custom script to the Scripts folder.

With the user exit script added to the deployment share (in this case, Z-RAMTest.wsf), it must then be referenced in the CustomSettings.ini file for the deployment share so it is called during deployment.

To call the user exit script from CustomSettings.ini

1.   Click Start, and then point to All Programs. Point to Microsoft Deployment Toolkit, and then click Deployment Workbench.

2.   In the Deployment Workbench console tree, go to Deployment Workbench/Deployment Shares/deployment_share (where deployment_share is the name of the deployment share to configure).

3.   In the Actions pane, click Properties.

4.   Click the Rules tab to display the CustomSettings.ini file.

5.   Add sections to UserExit.vbs to call the required functionality using the principles described in the previous section. An example CustomSetting.ini file is shown in Listing 27.

6.   Click OK to submit the changes.

7.   In the details pane, click deployment_share (where deployment_share is the name of the deployment share to configure).

8.   In the Actions pane, click Update Deployment Share.

The Update Deployment Share Wizard will start.

9.   On the Options page, select Optimize the boot image updating process, and then click Next.

10. On the Summary page, verify the details are correct, and then click Next.

11. On the Confirmation page, click Finish.

Another common use for the user exit script is to dynamically set the computer name from known MDT 2010 properties such as SerialNumber, Model, or Product.

Listing 27. Example CustomSettings.ini for Calling the User Exit Script

[Settings]

Priority=Default

[Default]

OSInstall=Y

TaskSequenceID=#SetTaskSequence(“%MEMORY%”)#

UserExit=Z-RAMTest.vbs

UserDataLocation=NONE

SkipAppsOnUpgrade=NO

SkipCapture=YES

SkipAdminPassword=NO

SkipProductKey=YES

Another example of a User Exit script setting the WDS Server name

You can also use %WDSServer%, however that variable work work when launched from an existing OS or boot media.

This example is from Johan Arwidmark’s blog.

Bootstrap.ini
[Default]
UserExit=UserExit.vbs
DeployRoot=\\#GetWDSServerName#\Distribution$

UserExit.vbs
Function UserExit(sType, sWhen, sDetail, bSkip)
                oLogging.CreateEntry “entered UserExit “, LogTypeInfo
                UserExit = Success
End Function

Function GetWDSServerName
                oLogging.CreateEntry “Entered UserExit Function ‘GetWDSServerName’”, LogTypeInfo
                on error resume next
                oShell.run “wpeutil updatebootinfo”, 1, true

                sWDSServerName = oShell.RegRead(“HKLM\System\CurrentControlSet\Control\PEBootServerName”)
                sWDSServerName = Left(sWDSServerName, InStr(sWDSServerName ,”.”)-1)

                oLogging.CreateEntry “WDSServerName = ” & sWDSServerName, LogTypeInfo
                oLogging.CreateEntry “Exiting UserExit Function ‘GetWDSServerName’”, LogTypeInfo

                GetWDSServerName = sWDSServerName
End Function