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:
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.
Adding a custom variable to 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.
Happy deployment, Johan