Changing the Deployment Package for an existing Automatic Deployment Rule in ConfigMgr 2012

ChanConfDeplPackA few months ago I did a post about Changing the Deployment Package linked to an Automatic Deployment Rule in ConfigMgr 2012. That post was about using PowerShell for changing the Deployment Package of an existing Automatic Deployment Rule (ADR). As I see that the script is being downloaded often, and I get some good questions about it, I thought it would be a good time for a small follow-up.

Even though the script will still work in ConfigMgr 2012 R2, it will not be needed anymore! Microsoft addressed the issue in R2 by adding a new tab, named Deployment Package, to the Properties of an ADR (see screenshot).

Changing the Deployment Package linked to an Automatic Deployment Rule in ConfigMgr 2012

This week I want to devote a post to changing the Deployment Package, which is linked to an Automatic Deployment Rule. I came on this subject as I got and read some questions about it. Actually it was not just that, also the fact that the answer was usually, that it’s not possible, at leas not via the console. As I couldn’t imagine that it’s not possible I went on a small research to see where it’s stored and how we can change it.

XML and WMI

Let’s start with where it’s stored. In WMI it’s stored in the class SMS_AutoDeployment and then the property ContentTemplate. Here it’s stored in XML format, like this:

<?xml version="1.0" encoding="utf-16"?><ContentActionXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><PackageID>PTP00027</PackageID><ContentLocales><Locale>Locale:9</Locale><Locale>Locale:0</Locale></ContentLocales><ContentSources><Source Name="Internet" Order="1"/><Source Name="WSUS" Order="2"/><Source Name="UNC" Order="3" Location=""/></ContentSources></ContentActionXML>

PowerShell

Now let’s go to the cool part, how do to change the package id that’s in the ContentActionXML. Well it’s actually quite easy with common XML parsing. To get all ins-and-outs about that, read this great article on the Hey, Scripting Guy! Blog. The first I needed, was to get a direct instance of the specific Automatic Deployment Rule. For that I used the following command:

[wmi]$AutoDeployment = (Get-WmiObject -Class SMS_AutoDeployment -Namespace root/SMS/site_$($SiteCode) -ComputerName $SiteServer | Where-Object -FilterScript {$_.Name -eq $AutoDeploymentName}).__PATH

The second thing I needed to do, was to get the XML content of the ContentTemplate property. For that I used the following command:

[xml]$ContentTemplateXML = $AutoDeployment.ContentTemplate

The third thing I needed to do, was to write the new package id to the PackageId property the ContentActionXML.The nice thing here, is that the different parts of the XML content can now be accessed as properties. So I used the following command to change the package id:

$ContentTemplateXML.ContentActionXML.PackageId = $PackageId

The fourth thing I needed to do, was to write the XML content back to the ContentTemplate property. For that I used the following command:

$AutoDeployment.ContentTemplate = $ContentTemplateXML.OuterXML

The last thing was to save the changes to the Automatic Deployment Rule and for that I used the following command:

$AutoDeployment.Put()

Conclusion

It was actually quite simple to change the Deployment Package, which is linked to an Automatic Deployment Rule, even though it’s not possible via the console. To see if the changes applied, either run the Automatic Deployment Rule and check the ruleengine.log, or run the Get-CMSoftwareUpdateAutoDeploymentRule cmdlet. With the combination of ConfigMgr, WMI, XML and PowerShell, there is little that can’t be changed!

The complete code (and usage) is available via the TechNet Galleries.