Using Collection variables in SCCM Task Sequence

Benoit LecoursOSD, SCCM25 Comments

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

For this post, I’ve build a little scenario to explain it to you.

Let’s say you are working in an international company and use SCCM to deploy operating system. Each offices has their 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 speedup 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 :

Create your OSD Collections

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

Collection variables Task Sequence

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

Collection variables Task Sequence Collection variables Task Sequence

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

Collection variables Task Sequence

Open your task sequence and create condition based on those variable

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

  • Open Software Library\Overview\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

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

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

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 done 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 Chalotte to use their respective collections.

When the task sequence run, 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

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

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

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

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.

25 Comments on “Using Collection variables in SCCM Task Sequence”

  1. 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?

  2. 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 ?

  3. 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?

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

  4. 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?

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

      1. 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 ?

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

    1. 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:D2}” -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.

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

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

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

      1. Unless you use the PS App Deploy Toolkit and use some PowerShell magic to collect that variable at run time.

  9. Pingback: Designing dynamic OSD environments and task sequences | Potent Engineer

Leave a Reply

Your email address will not be published. Required fields are marked *