Microsoft Configuration Manager 2012 and Powershell–Create Deployments

1 minute read

Hi all,

here another quick script I wrote to deploy a specified Task Sequence to a given collection.

This was a real quick one, as I could find out all the required values through WMIExplorer (thanks to ), some self-made WMI queries and SMSProv.log (always look in here for help!!!)

So here’s my script:

$sitename = "PRI"

function create-TSDeployment{

  $targetcoll = gwmi -ns "rootSMSSite_$sitename" -class SMS_Collection | WHERE {$_.Name -eq 'Install WinXP'} #if you want to deploy to multiple collections, you'll need to replace the name here

  $collID = $targetcoll.CollectionID
  $collName = $targetcoll.Name
  $TS = Gwmi -ns "rootSMSSite_$sitename" -class SMS_TaskSequencePackage | WHERE {$_.Name -eq 'Install XP'} #place TS Name in here
  $TSID = $TS.PackageID
  $TSName = $TS.Name
  $AdvName = $TSName+"_"+$TSID+"_"+$collName
  $AdvArgs =  @{
    AdvertFlags = 42860576;
    AdvertisementName = "$AdvName";
    CollectionID = $collID;
    PackageID = $TSID;
    ProgramName = "*";
    RemoteClientFlags = 8480;
    SourceSite = $sitename;
    TimeFlags = 8193

  Set-WmiInstance -Class SMS_Advertisement -arguments $AdvArgs -namespace "rootSMSSite_$sitename" | Out-Null


As my customer would like to deploy one Task Sequence to round about 150 collections, I will have to build a for-each loop to fill in the correct target collection name.


For more information on the SMS_Advertisement WMI class, see

There you’ll find more about the AdvertFlags, RemoteClientFlags and TimeFlags, as you will configure your deployment via these values, e.g “Deployment is available” or “Deployment is required and allowed to PXE”.

Any questions? Contact me here or via Twitter @david_obrien


Leave a Comment