Deploy Applications in a Task Sequence

We have many Applications in our Organisation. Lets say we have “Room1”, “Room2” and “Room3”. All these rooms are a own Collection. So we create a deployment for every application to the collection. But the rooms have different Application Inventory. Furthermore we have a “InstallOS” Collection which will install the OS. For example we have following collections:

  • Room1
  • Room2
  • Room3
  • InstallOS (Computers in this collection will be installed with PXE)

You can install Applications in the Task Sequence with the following option.

ts_deploy_1

You have two choices. The first option is “Install the following applications” and “Install applications according to dynamic variable list”.
The first option is only for a maximum of 10 Applications. In my case we have about 90 Applications and so this was no option. Moreover this method is very “Static”. If a Deployment changes you must also change the Task Sequence. This is not very useful.

The second option is more reliable. This option will take some Collection Variables to install Applications. For this to work you need a special naming convention for the Collection Variable. You need a common suffix and then a numbering starting at 01. For example: Room101, Room102, Room103

ts_deploy_2

Now we must create the Collection Variables. I have created for every room an suffix with the numbering and the application name. For example here you see:

ts_deploy_3

These Varialbes must be created on the “InstallOS” Collection. This is the collection where you put in the computers to install over PXE and where the Task Sequence is deployed.

As you can see now, you have hard time to enter this Collection Variables if you have many Applications. In my case i have to do more then 1000 entries. If you don’t automate this you will be never finished. So i have created a little Powershell Script that do this work for me. This script will look for all Deployments for a room (Room1, Room2 and Room3) and will delete all existing Collection Variables on the InstallOS Collection and then create a Collection Variable for each Application with the correct numbering. First start a Powershell and load the Configuration Manager module and set the location.

Import-Module -Name "$(split-path $Env:SMS_ADMIN_UI_PATH)\ConfigurationManager.psd1"
Set-Location YourSiteName:

After this you can start the script. The script looks like this:

########################################################################
############### Update-CollectionVariable ##############################
########################################################################

Write-Host "SCCM - Update-CollectionVariable" -ForegroundColor Green
Write-Host "Version 1.0" -ForegroundColor Green

# Global Variables (These must be changed)
$collection_install="InstallOS"
$room_list = @("Room1", "Room2", "Room3")

### Remove Previous Variables
function Remove-OldCollectionVariable
{
$remove_variablename = Get-CMDevicecollectionVariable -collectionName $collection_install

ForEach ($remove_item in $remove_variablename.Name)
    {
        Remove-CMDevicecollectionVariable -collectionName $collection_install -VariableName $remove_item -Force | Out-Null
    }
}

### Add Variables
function Add-CollectionVarialbe
{
    param ($room)

    # Declare Variables
    $i = 1

    ForEach ($item in Get-CMDeployment -collectionName $room)
    {
        $softwarename = $item.SoftwareName
        Write-Host $room' - '$softwarename -ForegroundColor Cyan

        $variablename_lt = $room+"0"+$i
        $variablename_gt = $room+$i

        if ($i -lt 10) {
            New-CMDevicecollectionVariable -collectionName $collection_install -VariableName $variablename_lt -Value $softwarename | Out-Null
        }
        else 
        {
            New-CMDevicecollectionVariable -collectionName $collection_install -VariableName $variablename_gt -Value $softwarename | Out-Null
        }
        $i++
    } 
}

### Main Function

# Remove Old Variables
Remove-OldCollectionVariable

# Add new
foreach ($room_element in $room_list) {

    Write-Host ""
    Write-Host "Add-CollectionVariable: " $room_element
    Write-Host ""

    Add-CollectionVarialbe -room $room_element
}

This script will run about 30 minutes in my environment but it depends on your size. This script should run every time you edited the Deployments. I have created a Cronjob for this. It starts this Powershell script every day.
If you have your Collection Variables you can edit your Task Sequence. It should look something like this:

ts_deploy_4

ts_deploy_5

As you can see i created a WMI Query to look for the Room. In my case the Room is in the Computername.

SELECT * FROM Win32_ComputerSystem WHERE Name LIKE 'Room1-%'

Attention

Installing Applications from Task Sequence will only work if you enable following option:

ts_deploy_6

By default this option is not enabled. You can enable this on all your applications with following short Powershell Script:

#########################################################################
############### Enable-TaskSequence-Deployment ##########################
#########################################################################

Write-Host "SCCM - Enable-TaskSequence-Deployment" -ForegroundColor Green
Write-Host "Version 1.0" -ForegroundColor Green

$name = Get-CMApplication -Name *

ForEach ($item in $name)
{
Write-Host $item.LocalizedDisplayName -ForegroundColor Red
$item_new = $item.LocalizedDisplayName
Set-CMApplication -AutoInstall $True -Name $item_new -Verbose
}

Leave a Reply

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