Script Use in Microsoft Deployment
Scripts provide the automation of the image build and overall deployment process. They scan the configuration files, query the configuration database, evaluate environment variables to determine the rules to be used when deploying the images to the target computers, and perform many other intricate deployment tasks. Microsoft Deployment uses both Microsoft Visual Basic® Scripting Edition (VBScript—.vbs) and Windows Script file (.wsf) scripts. Typically, there is no need to modify one of the delivered scripts, but an imaging team may occasionally need to make modifications. Instead of modifying one of the delivered scripts, copy the script to a new file, update it, and thoroughly test the effect of any change.
The scripts create log files as the scripts automate the deployment process. The log files record the status of the deployment process and can be used to assist in troubleshooting this process.
On This Page
Develop Custom Scripts
Create New Scripts
Develop Custom Scripts
Team members can develop new scripts for use in LTI and ZTI deployments. These scripts should be in the form of .vbs or .wsf files. For examples of scripts that Deployment Workbench uses, open the installation path of the distribution share, and then open the Scripts folder. Team members can customize these scripts for their own use at their own risk.
Before describing how to create a script, it is best to review how the scripts included with Microsoft Deployment are constructed. The standard Microsoft Deployment script is a .wsf file, which allows references to be made to functions that are contained in other scripts. Microsoft Deployment scripts leverage this functionality by referencing a script called ZTIUtility.vbs”.ZTIUtility.vbs , which is used to initialize the Microsoft Deployment environment and setup classes.
The script defines several standard objects that need not be declared in the script:
oFSO. File System Object
oShell. Wscript Shell object
oEnv. Process Environment object
oNetwork. WScript Network object
Four classes are defined that perform several standard tasks:
Environment. This class configures environment variables gathered through Windows Management Instrumentation (WMI) and Microsoft Deployment rule processing and allows team members to reference these directly I from the script.
Logging. This class provides the logging functionality that all Microsoft Deployment scripts use, creating a single log file for each script and a consolidated log file of all scripts.
Utility. This class provides general utility functionality.
Database. This class performs functions such as connecting to databases and reading information from databases.
Environment Class
This class is referenced in scripts through the oEnvironment object. For example, change the computer name to Example by using the following command:
oEnvironment.Item("ComputerName") = "Example"
Or, to determine whether this is a 32-bit or 64-bit architecture, query the architecture by using the following command:
oEnvironment.Item("Architecture")
Logging Class
This class is referenced in scripts through the oLogging object. When creating a informational log entry, use the following command:
oLogging.CreateEntry "Informational message", LogTypeInfo
When creating an error log entry, use the following command:
oLogging.CreateEntry "An error occured“,LogTypeError
Utility Class
This class is referenced in scripts through the oUtility object. To determine the name of the current script, use the following command:
oUtility.ScriptName
To find the location of a file, use the following command:
iRetVal = oUtility.FindFile("CustomSettings.ini", sIniFile)
Database Class
This class is referenced in scripts through the oDatabase object. There is generally no need to use the database class directly; instead, use rule processing to perform database lookups.
Create New Scripts
Team members can develop new scripts for use in LTI and ZTI deployments. These scripts should be in the form of .vbs or .wsf files. For examples of scripts that Deployment Workbench uses, open the installation path of the distribution share, and then open the Scripts folder. Team members can customize these scripts for their own use at their own risk.
Team members can also develop scripts for use in the imaging process and call them by adding them to the Task Sequence Editor and ultimately adding them to the TS.xml file. Listing 1 shows a template for creating custom scripts.
Listing 1. Custom script template
<job id="Z-Sample"> <script language="VBScript" src="ZTIUtility.vbs"/> <script language="VBScript"> ' //*************************************************************************** ' // ***** Script Header ***** ' // ' // Solution: Solution Accelerator for Business Desktop Deployment ' // File: Z-Sample.wsf ' // ' // Purpose: Template ' // ' // Usage: cscript Z-Sample.wsf [/debug:true] ' // ' // Customer Build Version: 1.0.0 ' // Customer Script Version: 1.0.0 ' // Customer History: ' // ' // ***** End Header ***** ' //*************************************************************************** '//---------------------------------------------------------------------------- '// '// Global constant and variable declarations '// '//---------------------------------------------------------------------------- Option Explicit Dim iRetVal '//---------------------------------------------------------------------------- '// End declarations '//---------------------------------------------------------------------------- '//---------------------------------------------------------------------------- '// Main routine '//---------------------------------------------------------------------------- On Error Resume Next iRetVal = ZTIProcess ProcessResults iRetVal On Error Goto 0 '//--------------------------------------------------------------------------- '// '// Function: ZTIProcess() '// '// Input: None '// '// Return: Success - 0 '// Failure - non-zero '// '// Purpose: Perform main ZTI processing '// '//--------------------------------------------------------------------------- Function ZTIProcess() iRetVal = Success ZTIProcess = iRetval '!!!!!!!!!!! INSERT YOUR CODE HERE !!!!!!!!!!!! End Function </script> </job>
At a high level, complete these steps to add a custom script:
Create the script based on the template.
Place the script in the \Distribution\Scripts folder.
Create an application in Deployment Workbench that references this script.
Add the application to the build task sequence.
Follow these guidelines when creating a script:
Always declare variables.
Only create objects where required, because Microsoft Deployment includes most objects that are needed.
Verify that the ZTIUtitlity provides the functionality required before writing a function.
Script names should always start with a Z , because Microsoft Deployment replicates only those scripts beginning with Z to other deployment points.
Listing 2 shows an example of a script that checks for an Encrypting File System (EFS) key and beta 2007 Microsoft Office system code on the target computer.
Listing 2. Script to Check for EFS Keys or Beta Versions of the 2007 Office System
<job id="LTIGetFolder"> <script language="VBScript" src="ZTIUtility.vbs"/> <script language="VBScript" src="WizUtility.vbs"/> <script language="VBScript"> ' //*************************************************************************** ' // ' // Microsoft IT Verify ' // ' // Verify that the local machine is ready for installation.... ' // ' // Checks to see if you have any EFS Keys, or a beta version of Office 2007 ' // ' //*************************************************************************** Option Explicit '//---------------------------------------------------------------------------- '// Main routine '//---------------------------------------------------------------------------- Dim iRetVal On Error Resume Next iRetVal = ZTIProcess ProcessResults iRetVal On Error Goto 0 '//--------------------------------------------------------------------------- '// '// Function: ZTIProcess() '// '// Input: None '// '// Return: Success - 0 '// Failure - non-zero '// '// Purpose: Perform main ZTI processing '// '//--------------------------------------------------------------------------- Function ZTIProcess() dim CheckForEFS, sError ZTIProcess = Success If oEnvironment.Item("DeploymentType") = "UPGRADE" then ' -------------------------------------------------------- ' Check for EFS keys in the registry. On Error Resume Next CheckForEFS = empty CheckForEFS = oShell.RegRead("HKCU\Software\Microsoft\Windows NT\CurrentVersion\EFS\CurrentKeys\CertificateHash") On Error goto 0 if not isempty(CheckForEFS) then sError = "Warning: Please backup your EFS certificate." & vbNewLine & "More info: https://go.microsoft.com/fwlink/?LinkId=79038" oLogging.CreateEntry sError, LogTypeWarning if MsgBox(sError & vbNewLine & "Press OK to continue", vbOKCancel) = vbCancel then ZTIProcess = Failure exit function end if end if ' -------------------------------------------------------- ' Ensure there are no old versions of Microsoft Office 12 on the local machine. if HasOldOffice then sError = "Warning: Please Manally remove all Beta Office 12 Components." oLogging.CreateEntry sError, LogTypeWarning if MsgBox(sError & vbNewLine & "Press OK to continue", vbOKCancel) = vbCancel then ZTIProcess = Failure exit function end if end if end if ZTIProcess = Success End Function Function HasOldOffice DIM oApplications, oApplication DIM sQuery ' Enumerate through all applications installed on the local machine, Looking for pre-RTM Office versions. sQuery = "(Name LIKE 'Microsoft Office%2007' or Name LIKE 'Microsoft Expression Web') and Version <> '12.0.4518.1014'" set oApplications = objWMI.ExecQuery("SELECT * FROM Win32_Product WHERE " & sQuery) HasOldOffice = oApplications.Count > 0 for each oApplication in oApplications ' Filter out MUI and Proof Packages if instr(1, oApplication.Name, "MUI", vbTextCompare ) = 0 and instr(1, oApplication.Name, "Proof", vbTextCompare ) = 0 then oLogging.CreateEntry "Old version of: '" & oApplication.Name & "' = " & oApplication.Version , LogTypeWarning end if next end function </script> </job>
To add a custom script to a task sequence
Open Deployment Workbench, and then expand Distribution Share.
Right-click task_sequence (where task_sequence is the name of the task sequence to edit), and then click Properties.
Click the Task Sequence tab.
Click Add, click General, and then click Run Command Line. Select the script to run in the task sequence by adding it to the Command Line box. Leave Start in blank, and then click OK to complete the procedure.
Note To avoid excessive use of the Up and Down buttons to move the application installation task, select the appropriate section in the task sequence, and then add the task.
After completing this process, Deployment Workbench updates the TS.xml file with the changes.
Download
Get the Microsoft Deployment Solution Accelerator
Update Notifications
Sign up to learn about updates and new releases
Feedback