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
}

SCCM 2012 – Add / Edit Deployments with Powershell

  • Add a Deployment for an Application (Application Available / User Information)
    Start-CMApplicationDeployment -CollectionName "Collection Name" -Name "Softwarename" -DeployAction Install -DeployPurpose Available -UserNotification DisplayAll -AvaliableDate (Get-Date) -AvaliableTime (Get-Date) -Verbose
  • Add a Deployment for an Application (Application Requierd / No User Information)
    Start-CMApplicationDeployment -CollectionName "Collection Name" -Name "Softwarename" -DeployAction Install -DeployPurpose Required -SendWakeUpPacket $True -UserNotification HideAll -AvaliableDate (Get-Date) -AvaliableTime (Get-Date) -RebootOutsideServiceWindow $True -OverrideServiceWindow $True -Verbose
  • If you have should create more Deployments for an Application following script should help:

    Import-CSV $filepath -Header Software, Room | Foreach-Object{
        Start-CMApplicationDeployment -CollectionName $_.Room -Name $_.Software -DeployAction Install -DeployPurpose Required -SendWakeUpPacket $True -UserNotification HideAll -AvaliableDate (Get-Date) -AvaliableTime (Get-Date) -RebootOutsideServiceWindow $True -OverrideServiceWindow $True -Verbose
    }
    

    This CSV File has two colums. The first is the Softwarename and the second is the Room (The Room is in my case the Collection Name). To run the script you must before allow scripts with following command:

    Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process
    
  • If you want to edit a Deployment follwing command is an example. Please note that the AvailableDate/Time and DeadlineDate/Time is the same. This results in that the Installation Deadline is set to “As soon as possible after the available time”
    Set-CMApplicationDeployment -ApplicationName $_.Software -CollectionName "Collection Name" -AvaliableDate 2014/06/29 -AvaliableTime 11:22 -DeadlineDate 2014/06/29 -DeadlineTime 11:22 -SendWakeUpPacket $True -UserNotification DisplaySoftwareCenterOnly -RebootOutsideServiceWindow $True -OverrideServiceWindow $True -Verbose

 

Deploy Skype without Desktop Shortcut / Autostart

You have the choice to deploy Skype silent, with the .msi Installer from Skype Business. The Problem is that the built in .mst files for me not working. See here for more info:

http://community.skype.com/t5/Windows-desktop-client/Unattended-install/m-p/184740#M18609

So i create a own .mst File with the changes. First of all i want to prevent the automatic startup of skype. So you must delete following line, in the Registry Table. (I use InstEd to create a .mst file)

skype

Furthermore i have deleted also the Desktop Shortcut in the Shortcuts Table. To apply the .mst File run following command:

msiexec.exe /i SkypeSetup.msi TRANSFORMS=skype.mst /qb