For this post, I’ve built a little scenario to explain how to use SCCM Collection variables in Task Sequence.

I get often asked how to reduce the number of SCCM task sequences and how to make them dynamic. I’m always surprised when I hear from an SCCM administrator that they don’t use variables in their task sequence.

Let’s say you are working in an international company and use SCCM to deploy operating systems. Each office has its own configuration and specific software to install. You decide to create 1 task sequence per office. Wrong! You’ll end up in a management nightmare. One task sequence is often enough and this is where you need variables to the rescue.

The magic that you need to understand is collection variables. You have 2 choices, let the user enter the variable value at the beginning of the deployment (explain later) or pre-load these values using collection variables. I prefer the second option which speeds up the deployment process.

Scenario :

  • You manage SCCM for 3 offices (Alabama,Boston and Charlotte)
  • Each Office have a different Administrator password, different timezone, place their computer in different OU in Active Directory
  • Alabama Office needs Office 2010, Adobe Flash 15 and 7zip
  • Boston Office needs Office 2013 and Adobe Flash 11
  • Charlotte Office needs Adobe Acrobat Reader XI

Here is how to achieve this :

SCCM Collection variables Task Sequence Step-by-Step Guide

#1 – Create your OSD Collections

Create 1 collection per office. For this post, I created 3 collections Offices in Alabama, Boston, and Charlotte. Each Office will receive different configurations and software based on their variables.

SCCM Collection variables Task Sequence

#2 – Create your Office variable

  • Right click the Alabama collection
  • Select Properties
  • Select the Collection Variables tab
  • Click the star icon
  • Create a new variable named Office
  • Give it a value of Alabama
  • Repeat steps for Boston and Charlotte collection

You’ll end up with 3 collections with their variables having different values.

Collection variables Task Sequence

#3 – Open your task sequence and create condition based on those variable

*I assume that you already have a functional task sequence.

  • Open Software Library \ Operating Systems \ Task Sequences
  • Right Click your task sequence
  • Select Edit
  • To place the computer account in a specific OU :
    • Browse to the Apply Network Settings Section
    • Create 3 Apply Network Settings steps, 1 for each site
    • Click Add, Setting, Apply Network Settings
    • On each Office configure the Name and Domain OU to fits your needs
SCCM Collection variables Task Sequence
  • On the Options Tab
  • Click Add Condition
  • Select Task Sequence Variable
  • Enter the variable name Office
  • Condition : Equal
  • Value : Alabama
Collection variables Task Sequence
Collection variables Task Sequence

***Repeat above steps for Boston and Charlotte changing the value of the variable***

  • Browse to the Apply Windows Settings Section
  • Create 3 Apply Windows Settings steps, 1 for each site
  • Click Add, Setting, Apply Windows Settings
  • On each Office configure the TimeZone and Administrator password
SCCM Collection variables Task Sequence
  • On the Option Tab
  • Click Add Condition
  • Select Task Sequence Variable
  • Enter the variable name Office
  • Condition : Equal
  • Value : Alabama
Collection variables Task Sequence

***Repeat above steps for Boston and Charlotte changing the value of the variable***

  •  Browse after the Setup Windows and Config step
  • Click Add, General, Install Application
  • Create 3 Install Application steps, 1 for each site
  • On each step configure the desired software
SCCM Collection variables Task Sequence
  • On the Option Tab
  • Click Add Condition
  • Select Task Sequence Variable
  • Enter the variable name Office
  • Condition : Equal
  • Value : Alabama

***Repeat above steps for Boston and Charlotte changing the value of the variable***

Summary

So what we basically did in the previous steps is told the task sequence to run our step based on the Office variable value.

Next, you need to deploy your task sequence to the 3 collections. Ask your IT guys in Alabama, Boston, and Charlotte to use their respective collections.

When the task sequence runs, it will evaluate each step and run only the Alabama step when in the Alabama collection, the Boston step when in the Boston collection, and the Charlotte step when in the Charlotte collection.

Verification

  • Start a task sequence
  • Open Monitoring\Overview\System Status\Status Message Queries
  • Select All Status Messages from a Specific System
  • Enter your machine name and select 1 hour ago
SCCM Collection variables Task Sequence
  •  Follow the installation process
  • Then the task sequence evaluate a variable you’ll see this message
1766 (11)
  • You will see when your variable gets skipped meaning that it works

SCCM Collection variables Task Sequence – Extra

If you prefer to have only 1 collection for OSD and ask you IT people to fill in the Office variable, you can achieve that easily.

  • Do the same procedure but create only 1 collection for OSD
  • Create the Office variable on this collection but leave the value empty
SCCM Collection variables Task Sequence
  • Doing so, the task sequence will start and wait for a value to be entered in the Office variable
  • Double-click the value and enter Alabama, Boston or Charlotte and the task sequence will deploy options based on the designated office
Collection variables Task Sequence

From there, only imagination is the limit. You now understand the power of the variable in a task sequence. Use it in order to maintain the lowest amount of task sequence in your organization.

Read more about variables on Technet.

You can create you collection variable using PowerShell but for now, the cmdlet is broken in CU3. If you need to script the variable creation you must use WMI function for now.

Comments (28)

klonk

10.05.2021 AT 02:57 PM
I love your idea and I was able to build it, but it does nothing and the task sequence status shows everything false. I have 15 distribution points all over the world and I made variable "SiteName" in the collections referencing the distribution points pointing towards the country they represent. I then built the Apply Network Settings group and Apply Windows Settings group and used this SiteName variable in options and subsequently setup the network domain logon and set the OU. I am doing a OSD TS with Unknown Computer Collection and all of the aforementioned settings come back false. I guess the question is how does the Collections variable from a separate collection get seen in the task sequence in the first place. I guess I missed something.

klonk

10.06.2021 AT 05:00 PM
Me again. I figured it out. I am going to leave the Variable "SiteName" where it is for other circumstances such as feature updates or enhancements of existing devices. In the meanwhile I simply added it as a field into the Unknown Computers Collection and now it logs onto the domain and puts the device into the right OU and sets the timezone and language. Thank You again.

mih

04.22.2020 AT 07:14 AM
Good explanation thank you

AJP

08.02.2019 AT 10:26 AM
Great article, thanks for sharing. One problem I see with doing this is how does it handle new machines that won't be in SCCM and therefore not in the specific office collections? Would you have to go through the hassle of pre-creating the accounts before the computers can be imaged?

michel leard

07.17.2019 AT 09:57 AM
How would i pass a IP address for printer. I ask the ip of the printer in the collection variable. Then imade a TS that assign the port to the ip. example i want to assign to the ip 10.0.5.151 with this script in TS: CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\fr-FR\prnport.vbs -a -r "10.0.5.151" -o raw -n 9100 -h "10.0.5.151" Then i ask for the IPcopieur variable in the collection variable; then my script would become: CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\fr-FR\prnport.vbs -a -r IPcopieur -o raw -n 9100 -h IPcopieur (do i need "" in the variable declaration here?) Would this work ?

Ryan Cowell

05.31.2019 AT 06:52 AM
Hi there, I'm trying to implement this in SCCM CB (1902) but it doesn't work reliably. I'm doing new computer installations of Windows 10 1809. New computer objects are being created in AD and security groups are assigned to the object that will dictate what software is installed during OSD. I created device collections that query the security groups that are assigned to the computer object and assigned collection variables to each collection. The collection variable is then used to control whether an embedded task sequence runs within OSD or not and installs the necessary software required by the computer. Like I mentioned above this works but not reliably. I don't understand what I'm doing wrong? I suspect there might be an issue with the DDR that gets created for the computer object when OSD installs the configmgr client. Collection variable example: Role=AllDesktops Role=IT Role=HR Any suggestions on where I should be looking?

Ankush Chawla

07.23.2019 AT 08:52 PM
Hi Ryan, Just wondering how did you get with your above issue. We are also planning to do the deploy the application using the above method.

RM

05.08.2019 AT 03:44 PM
Thank you!

Vijay

01.16.2019 AT 11:35 PM
This information is very useful and very easy to understand. Thanks a lot for this useful info.

Stephan

07.19.2018 AT 07:53 AM
Hi, are only the variables on the collection used that the task sequence is targeted to? Or can I use a collection like "Install_Software_A" and add the computer and publish my task sequence to some other collection?

Nemanja Jovic

03.15.2018 AT 03:32 AM
Nice, thanks for sharing 🙂

Tom

02.06.2018 AT 11:19 AM
Thanks! Is there a list of Collection Variables for SCCM Current Branch? Thanks. tp

Matt

12.01.2016 AT 07:35 PM
Hi, I'm looking for the same functionality as using blank collection variables (prompting at TS execution), except per task sequence. Because of the way our collection environment shakes out, it's impossible to create a new collection for my new variables without causing undesirable changes in everyone's workflow. I know there are ways to use scripts to generate custom prompts during a TS, but I'd really like to stick to using the built-in collection variable prompt. Ideally I would like to still use blank collection variables, but simply add more to the pop up list presented when you select a TS, based on which TS you select. Any idea if this is possible, or the closest equivalent? Thanks for the great article and any insights you might have, == Matt

Twenty94470

10.05.2016 AT 03:49 AM
How it's possible to manage task Sequence with "Computer Variable" ? Thanks

Benoit Lecours

10.05.2016 AT 07:48 AM
Hi, This is what the post is about so i'm not sure i'm understanding your question 🙂

Twenty94470

10.06.2016 AT 03:30 AM
Ah ok, In a TS "Collection Variable" and "Computer variable" realize the same things. Do you know if we can realize a dynamic query in a collection to collect all computer how has a specific COMPUTER variable ?

Benoit Lecours

10.06.2016 AT 06:31 AM
This article contains a couple of tips for querying variables : http://it.peikkoluola.net/2013/09/30/display-a-sccm-collection-variable-and-its-value/

N. Boros

08.12.2015 AT 02:12 PM
Hello, I'm struggle with several collections that have each one only ONE APP base collection variable defined to only one application. Issue is that if my basevar is interrupted from chain like this : my PC belongs to collections with the following collection variable: APP01, APP02, APP03, and APP05 only first 3 applications will install, and the last one if is not APP04 assigned to the PC (PC is not in the collection with APP04 )will not. I have used ZTICOALESCE.WSF but still no luck. Also since I have collection specific to an application only, I tried for each collection to use APP01 and value of the application - in this case only first application (collection variable APP01) will install. Any ideas would be helpful. I want to target specific application to a specific machine, and not to target several application to a collection that contains most of the PCs. Thanks, NB

Aaron Whittaker

09.02.2015 AT 06:00 PM
I too found that the ZTICOALESCE.WSF didn't work for me, so I wrote my own. As long as the machine is in the collection at the beginning of the task sequence this should work. Run this script followed by the 'Install Application' step with the dynamic list option and it should work. $BaseApplicationName = "App" $tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment $appsInstallList = @{} $i = 0 foreach ($item in $tsenv.GetVariables()) { if ($item -like "$BaseApplicationName*"){ $appsInstallList.add($item, $tsenv.Value("$item")) } } foreach ($app in $appsInstallList.Keys) { $i ++ $varName = $BaseApplicationName+("{0😀2}" -f $i) $varValue = $appsInstallList.Get_Item($app) $tsenv.Value("$VarName") = $varValue } Reading over it the script could probably be consolidated but that's probably true of any of my early scripts as I learn more PowerShell.

Hasta

04.22.2015 AT 09:31 AM
Hi Benoit, tried to use empty variables to get filled by the administrator in beginning of the Task Sequence. Unfortunately there is no prompt at the start. Has there been any changes to that behaviour? Using SCCM2012 R2 (No CU yet) Thank you

Ankush

09.04.2017 AT 11:18 PM
Hi Benoit, I have got the same issue as the above user, any ideas why the wizard is not prompting to enter the value. Thanks for your help. Regards, Ankush

Matt Sample

10.04.2017 AT 06:30 PM
Empty value is also not working for me..

sanj

02.06.2015 AT 07:13 AM
Hey, can I pass a collection variable into a application in "Application management", for e.g. in the Programs > Installation program, "somecommandline.cmd" %variablefromcollection% regards

Benoit Lecours

02.06.2015 AT 08:30 AM
Unfortunately no, that's not possible.

Aaron Whittaker

09.02.2015 AT 05:56 PM
Unless you use the PS App Deploy Toolkit and use some PowerShell magic to collect that variable at run time.

turbomcp

01.21.2015 AT 05:18 PM
Awesome Thanks alot

Usha

12.13.2014 AT 05:35 PM
Hay too good,so so well explained Thank you gives us more.