Yesterday I got a question in my twitter feed (@jarwidmark) about how to create a custom variable in MDT 2013 using a script. The answer is, yes you can do that, but you rarely have to, because you can create them directly in CustomSettings.ini to begin with. Anyway, some times it does makes sense to dynamically create custom variables in a script. In this post I demonstrate a few different methods for creating a custom variable.
Going back to the source
First, built-in variables are documented in the MDT 2013 help file, found via the Deployment Workbench "Help" menu, or in the file system: C:Program FilesMicrosoft Deployment ToolkitBinMicrosoft Deployment Toolkit Documentation Library.chm (default location).
Then MDT has it's internal "document", the ZTIGather.xml file that lists the variables, and also defines their behavior. For example if a property should have "first-writer-wins" or "last-writer-wins". Here are few sample lines from the ZTIGather.xml file:
<!-- Properties that can be overwritten (last value wins) and are automatically set by the BDD scripts --> <property description="The UNC path to the deployment share" overwrite="true" type="string" id="DeployRoot"/> <property description="The drive letter mapped to the deployment share (Lite Touch only)" overwrite="true" type="string" id="DeployDrive"/> <!-- Properties that cannot be overwritten (first value wins) --> <property description="The new computer name to assign to the computer (used with ConfigMgr) " overwrite="false" type="string" id="OSDComputerName"/> <property description="TimeZone Identifier for Windows Vista Builds (example: PST = 'Pacific Standard Time')" overwrite="false" type="string" id="TimeZoneName"/>
Creating a custom variable using CustomSettings.ini
The most commonly used method to create a custom variable is to add it to your CustomSettings.ini file. Here is an example, where two custom variables (or properties) are used for
[Settings] Priority=HardwareInfo, Default Properties=MakeAlias, ModelAlias [HardwareInfo] UserExit=ModelAliasExit.vbs MakeAlias=#SetMakeAlias()# ModelAlias=#SetModelAlias()#
Creating a custom variable in the Task Sequence
Variables set in CustomSettings.ini are considered global by default, but you can create task sequence specific variable directly in the task sequence by adding a "Set Task Sequence Variable" action. Here is an example showing the custom HydrationMethod variable in a task sequence.
Creating a custom variable in a script
When needing variables created (or set) in a script, for example based on dynamic conditions, you can do that too by simply calling the task sequence object. This is exactly what the built-in ZTISetVariable.wsf script does, but you also find that most of the other MDT scripts do that as well.
<job id="ZTISetVariable"> <script language="VBScript" src="ZTIUtility.vbs"/> <script language="VBScript"> ' Create and set a custom varialble oEnvironment.Item("HydrationMethod") = "Simulate" </script> </job>
Happy deployment, Johan