How to: Exectue a ConfigMgr 2012 Auto Deployment Rule (ADR)

Here’s a quick example for how to initiate an ADR using PowerShell:

(gwmi sms_autodeployment -namespace root\sms\site_cas -computer MyServer -filter "Name='FEP Updates'").EvaluateAutoDeployment()

Replace CAS with your site code, and MyServer with the server name. My ADR is “FEP Updates”, so replace that with the desired ADR to run. Remember that ADRs are dependent on the WSUS synchronization, so if you re-evaluate the ADR without a new WSUS synchronization, you may not see any change in your ADR.

If you really want to party, and desire to re-run all ADRs, run the following command:

gwmi sms_autodeployment -namespace root\sms\site_cas -computer MyServer | foreach-object {$_.EvaluateAutoDeployment()}

This will find all ADRs, and call the EvaluateAutoDeployment method on each one.
Happy Scripting,

Greg

ramseyg@hotmail.com

Converting to/from WMI Date Time

You will find many posts for how to convert a wmi date-time string to a human-friendly date time here’s one example from Don Jones.

First, here’s an example of the wmi date-time string:

Get-WmiObject -class Win32_OperatingSystem  | select __Server, LastBootUpTime

The value for LastBootUpTime will look something like this: 20120718141700.473048-300. This output is very handy for alpha-sort, by the way…
And Here’s Don’s code:

Get-WmiObject -class Win32_OperatingSystem | Select-Object __SERVER,@{label='LastRestart';expression={$_.ConvertToDateTime($_.LastBootUpTime)}}

Notice how Don elegantly converts the string on the fly with the label and expression arguments.

Now here’s an example of using a COM object to convert the current date time to a wmi date-time string.

$wmidate = new-object -com Wbemscripting.swbemdatetime
$date = get-date -format g
$wmidate.SetVarDate($date,$true)
$wmidate.value

Not nearly as elegant, but it gets the job done. When you create objects in ConfigMgr that require a date-time field, you will usually enter a wmi date-time string.

 

Happy Scripting!

 

Greg