Creating custom variables in MDT 2013

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).

image
The MDT 2013 help file.

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.

image
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.

<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

About the author

Johan Arwidmark

5 1 vote
Article Rating
Subscribe
Notify of
guest
5 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Admin
Admin
8 years ago

Cool, thanks for the comment,

/ Johan

kantzy
kantzy
8 years ago

Figured out how to change the language based on the a custom variable we are setting in the wizard. Added the below in CS.ini and modified the Gather step in the TS to gather variables in CS.ini after the HTA wizard. Thanks for all you contribution. You guys rock.
[Settings]
Priority=LanguagePack, Default

[French]
LanguagePacks001={1c0991b3-2511-43ca-998c-e6ef31d7c950}

kantzy
kantzy
8 years ago

We have a custom wizard for Windows 7 created in MDT 2010 integrated with SCCM 2007. I have somehow managed to get the same wizard in MDT 2013 using which we will be deploying Windows 8.1 for tablets (without SCCM).In the HTA wizard we select a location based on which language, locale, time zone etc are auto selected. Language pack has a custom variable called "LanguagePack".Even UILanguage is set with the same values as "LanguagePack" variable (Just FYI) Can you please let me know how to install a specific language pack based on this custom variable called "LanguagePack"?Do i need… Read more »

Admin
Admin
8 years ago

Indeed, yes, thanks for pointing out that method. I use that a lot for on-the-fly-testing.

/ Johan

ITguyCharlie
ITguyCharlie
8 years ago

Lest we not forget, can always call some custom variables from the command line "Litetouch.wsf /TaskSequenceID:REF-BUILD /CustomVar:CUSTOM" Though more used for static variables, assuming Litetouch is called from some other script can always pass in dynamic variables too…


>