SCCM OSD Task Sequence Variables – A beginners guide

This article is an updated version of SCCM OSD Task Sequence Variables – A beginners guide
Updated on :   04/02/2015
Relevant to:   SCCM 2007 and 2012 (including R2 and R3 versions), MDT 2010/2012/2013


 

Task sequence variables can be leveraged within an SCCM task sequence to perform conditional branching and execution on SCCM Task Sequence Tasks and Groups, allowing us to execute tasks only on specific computers based on something identifiable about that computer.

For example, install VPN software only on laptops or specific drivers only on their corresponding models.  This type of functionality minimises the amount of duplication of Task Sequences required and, in many cases, results in only requiring one task sequence for clients and one for servers being required.

For the purposes of this article, I’ll break Task Sequence variables down into 3 types:

  • SCCM OSD variables
  • MDT 2010/2012/2013 variables
  • User Defined variables

 

SCCM OSD variables are built in Task Sequence variables that are available in any SCCM OSD deployment – most of these are set by SCCM and need not be changed (a lot of them are also read-only) – but, its handy to know what they are – in case, one day, you do need to manipulate one in order to get your task sequence working the way you want.

A full list of these variables can be found at:

SCCM 2007 – http://technet.microsoft.com/en-us/library/bb632442.aspx

SCCM 2012 – https://technet.microsoft.com/en-au/library/gg682064.aspx

 

MDT 2010/2012/2013 variables are SCCM Task Sequence the variables that are gathered by MDT’s ZTIGather process and are documented in “Toolkit Reference.doc” that comes with the MDT 2010/2012/2013 install. The easiest way to get the additional variables offered by MDT 2010/2012/2013 is to configure MDT integration for SCCM, and use the MDT Task Sequence Wizard in the SCCM console to create a task sequence based on one of the MDT template task sequences (which I recommend to use anyway).

It is important to stress that the MDT variables created by integrating MDT into SCCM are additional to the base SCCM variables – and present one of the main reasons for installing MDT on top of your SCCM install.

A full list of these variables can be found at:

MDT 2012 – http://download.microsoft.com/download/b/3/a/b3a89fae-f7bf-4e7c-b208-223b991e9c30/Optional%20-%20MDT%202012%20Print-Ready%20Documentation.zip (Located within Toolkit reference.doc)

MDT 2013 – http://download.microsoft.com/download/B/F/5/BF5DF779-ED74-4BEC-A07E-9EB25694C6BB/MDT%202013%20Documentation.zip (Located within Toolkit reference.doc)

 

User defined variables are passed to the Task Sequence when the Task Sequence starts execution, and can be stored either in an SCCM Resource, or an SCCM collection, and are anything you wish to define. An example of usage here would be to define a variable called “Department”, and based on its value, install software specific to that department.

 


 

How do you find out what a specific variable you want to use is?

You want to perform a task sequence step based on the model of a machine, you know the model is a Dell Latitude E6520, but, what does SCCM see it as?

There are a number of ways to achieve this goal, you can:

 

Example of using WMIC to get a computers model name:

OSDTSVariables1

Example of using an SCCM query to get a computers model name:

OSDTSVariables2

Example output from smsts.log

OSDTSVariables3

Example output from ztigather.log

OSDTSVariables4




 

SCCM/MDT TS Variable Examples

Issue:

You have a large number of hardware make/models and instead of using driver categories, you prefer to apply driver packages based on model.

 

How to obtain the model information:

Discussed in detail above, but I think the quickest way is – from your full OS (XP/Vista/Win7/Win8.1) run the following command:

WMIC CSProduct Get Name

 

From this you will get the model name as WMI (and therefore SCCM and MDT) sees it. Unfortunately, some hardware manufacturers decide to be, what can only be described as “not-deployment-focused”. Some examples of model strings you will see are:

 

Latitude D500 – nice and simple

DC 7900 FRGHU89m – we like the DC 7900 part, but the addition letters represent nothing to us and are just pain

9645-AM2 – Then we have the worst of the lot, the Lenovo’s….. where this is a M55e

 

How to use this:

This is where it can get a little tricky – as there are 3 different scenarios:

1)      If you are using MDT integration and the model name is nicely formatted, you can use the task sequence variable “Model”

Example: Model equals Latitude D500

OSDTSVariables5

2)      If you are using MDT integration and the model name is badly formatted, the “Task Sequence variable” doesn’t support “like”, therefore,   you must use WMI, instead, which does support the “like” statement and will allow us to use the wildcard “%”

Example: Select * from Win32_ComputerSystem WHERE model like “9645%”

OSDTSVariables6

 

3)      If you are not using MDT integration, you must use WMI

Example: Select * from Win32_ComputerSystem WHERE model like “9645%”

 


 

 

Issue:

You want to identify laptops, so you can install laptop specific software

How to obtain the chassis information:

This one can sometimes be a little tricky. You can use WMI to detect the chassis type, or detect if there is a battery in a machine, but every now and again, some laptops will not correctly report this information.

How to use this:

1)      If you are using MDT integration, the variables “ISLaptop”, “ISDesktop” and “ISServer” are available and provide a very quick and simple method of implementing this scenario.

Example: ISLaptop equals TRUE

2)      If you’re not using MDT integration, you can use another WMI query.

Example: Select * from Win32_Battery where availability > 0

 


 

Issue:

You want to the use site the build is occurring in to determine the time zone, OU, software to be installed etc

How to obtain the site information:

You should probably know which AD site or subnets relate to which to which clients – so you don’t need to really “obtain” this.

How to use this:

MDT does not provide us any cool methods using site variables in the GUI, so I’ll go through a different method a bit later, however, we can use WMI for this

Example1: Select * from Win32_NTDomain WHERE ClientSiteName LIKE ‘%Adelaide%

Example2: Select * FROM Win32_IP4RouteTable WHERE ((Mask=’255.255.255.255′ AND NextHop=’127.0.0.1′) AND (Destination Like ‘10.93.3%’ OR Destination Like ‘10.93.4%’)

Another option here is to customize your customsettings.ini, which will be available for those of you using MDT integration. This method is a bit more old-school, but for those of you coming from MDT backgrounds it may be more comfortable:

Example section CustomSettings.ini

[Settings] Priority=DefaultGateway,Default

[DefaultGateway]

192.168.0.1=Adelaide

192.168.10.1=Melbourne

192.168.20.1=Perth

[Adelaide]

TimeZone=255

MachineObjectOU=”OU=Adelaide,OU=Comps…. “

 


 

 

User defined Task Sequence variables examples

So you have your reference and prod task sequences all done, but you find that there are a set of applications for each department that need to be deployed – and at the moment you are assigning them post deployment, which works, but takes additional time and manual effort.

So, let’s add as variable to each SCCM resource record as we import it.

1)      Make up your CSV which contains MAC, ComputerName, Variable Value

OSDTSVariables7

2a)    In SCCM 2007 – Right click on OSD | Computer association

2b)    In SCCM 2012 – Assets & Compliance tab, highlight “Devices” and select “import computer information” from the toolbar

OSDTSVariables8

3)      Select “import computers from a file”

4)      Select your file and assign the PC name, the MAC and the variable field… and give the variable a name

OSDTSVariables9

5)      Import your records

6)      In your task sequence, add a TS Variable condition as per the entered values

OSDTSVariables10


 

Adding TS Variables based on collection

So you can also add TS variables based on collection membership of a machine

Simply go to a collection (that you may already have), properties and the “Collection variables” tab

OSDTSVariables11


 

Stacking and nesting

Task sequence variables can also be stacked and nested, so you are not confined to only using one piece of logic per TS task or group.

Stacking – This is the term I use when multiple conditions are added to a single TS task or group

OSDTSVariables12

Nesting – This is the term I use when conditions are nested within groups

The first condition is placed upon a group

OSDTSVariables13

Subsequent condition are placed upon tasks under the group

OSDTSVariables14



 

So, I hope that helps someone out there with how to use TS variables…. If anyone has any issues on how to better use TS variables, by all means, post a comment and I’ll try and help with a specific example in this article.

 



 

11 thoughts on “SCCM OSD Task Sequence Variables – A beginners guide

  1. …but how do we use these variables in the task sequence?

    For example, lets say I have a variable called ‘OU’ set on a collection. I want to use this variable name in the ‘Apply Network Settings’ step of a task sequence in the ‘Domain OU’ box, so that my image will place machines into the relevant OU when they are imaged. What should I type into the box…?

    1. Navigate to the appropriate step in your task sequence, select the “options” tab

      Add condition -> Task sequence variable
      Enter the name of the variable and the value you want it to match in order to execute the step

      1. That’s fine if I want to optionally execute a step, I understand that, but lets say I have 100+ OUs and I don’t want to create 100 ‘optional’ steps; I want to set a variable *on each collection* and use this variable in *one* task sequence step to choose which OU the put the machine.

        I’ve been searching around and the consensus seems to be to try %variable% but I’m unsure if I can just use my own variables, or if I have to set specific ones.

        1. Cant say ive ever been in that situation – over 100 OU’s for computer objects sounds excessive.

          Anyhoo – you could use a script to modify the variable before the set OU step – but this assumes there is something in the name etc that will also identify which OU it should belong in.

          You’d really be far better off asking this type of thing at somewhere like MYITForum – its a better environment for questions that need some detail….

  2. You only need one step in your TS. Create the Variable in each collection and call it the same e.g. DOMAINOU

    In the TS under Apply Network Settings simply reference %DOMAINOU% in the “Domain OU:” field and the TS will reference the variable from the collection your computer is in for the advertised TS.

    1. ahhh i love that… try and make it sound like some kind of revelation!

      anyhoo – yep, your completely right – but unless you are going to have all those colelctions for some other purpose, all your doing is moving the admin from one place to another….

Leave a Reply