Microsoft Configuration Manager 2012 and Powershell–Create Deployments

by David O'Brien on 03/17/2012 | 1 Comments | 7,083 Views

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 http://thepowershellguy.com/blogs/posh/archive/2007/03/22/powershell-wmi-explorer-part-1.aspx ), some self-made WMI queries and SMSProv.log (always look in here for help!!!)

So here’s my script:

   1:  $sitename = "PRI"
   2:   
   3:  function create-TSDeployment{
   4:  $targetcoll = gwmi -ns "root\SMS\Site_$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
   5:  $collID = $targetcoll.CollectionID
   6:  $collName = $targetcoll.Name
   7:   
   8:  $TS = Gwmi -ns "root\SMS\Site_$sitename" -class SMS_TaskSequencePackage | WHERE {$_.Name -eq 'Install XP'} #place TS Name in here
   9:  $TSID = $TS.PackageID
  10:  $TSName = $TS.Name
  11:  $AdvName = $TSName+"_"+$TSID+"_"+$collName
  12:   
  13:  $AdvArgs =  @{
  14:   AdvertFlags = 42860576; 
  15:   AdvertisementName = "$AdvName";
  16:   CollectionID = $collID;
  17:   PackageID = $TSID;
  18:   ProgramName = "*";
  19:   RemoteClientFlags = 8480; 
  20:   SourceSite = $sitename;
  21:   TimeFlags = 8193 
  22:   }
  23:   
  24:  Set-WmiInstance -Class SMS_Advertisement -arguments $AdvArgs -namespace "root\SMS\Site_$sitename" | Out-Null
  25:  }
  26:   
  27:  create-TSDeployment 

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.

SMS_Advertisement

For more information on the SMS_Advertisement WMI class, see http://msdn.microsoft.com/en-us/library/cc146108.aspx

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

1 responses for "Microsoft Configuration Manager 2012 and Powershell–Create Deployments"

I'm trying something similar

I'm trying something similar to this but can't figure out exactly how to have the script distribute the package immediately. Instead it's stating the the deployment time starts at 1/1/1990. Not sure if you've ever ran into this issue or have some insight on how to adjust this. Thanks!

Add Comment

Der Inhalt dieses Feldes wird nicht öffentlich angezeigt.
Sicherheitscode
Diese Frage hat den Zweck zu testen, ob Sie ein menschlicher Benutzer sind und um automatisierten Spam vorzubeugen.
Bild-CAPTCHA
reload image
Geben Sie die Zeichen ein, die im Bild zu sehen sind.

Microsoft Competence Blog

Application Infrastructure mit Microsoft Technologien ist ein wichtiges Fokusthema der sepago. Wir haben langjährige Projekterfahrung, sind neugierig auf neue Technologien und möchten diese bis in letzte Detail verstehen. Die Competence Blogs berichten davon.

RSS-Feed Alle Artikel des Competence Blogs abonnieren.

 

About the author

Bild von David O'Brien
David O'Brien
IT-Consultant
Blogs about VDI, AppDNA, Microsoft ConfigMgr and deployment topics in general are my "thing"

All articles

REcruiting Werbung 345