Automatic Deployment Rules: Change Software Update Package

Changing the Software Update Package reference of an Automatic Deployment Rule is not possible through ​the console.
With the following PowerShell script you can change the PackageID through WMI:


#################
# Configuration #
#################

$newPackageID = "PACKAGEID"
$siteCode = "SITECODE"
$serverName = "HOSTNAME"
# All rules matching the following search string will be updated
$searchString = "SUM *"

# See what's going to happen before changing anything
$test = $TRUE

#################
# Code          #
#################

$autoDeployments = Get-WmiObject -class "SMS_AutoDeployment" -namespace "root\sms\site_$siteCode" -impersonation 3 -computername $serverName | Where-Object {$_.name -like $searchString}
Write-Host
if ($test)
{
Write-Host "### TESTMODE - Nothing will be changed ###"
Write-Host
}

foreach ($item in $autoDeployments)
{
$item = [wmi]"$($item.__PATH)"
$xmlContentTempl = $item.ContentTemplate

Write-Host "Rule Name:"$item.Name
Write-Host "****************************************************"
Write-Host "PackageID:"$xmlContentTempl.ContentActionXML.PackageID

if ($test)
{
Write-Host "New PackageID would be:"$newPackageID
}
else
{
$xmlContentTempl.ContentActionXML.PackageID = $newPackageID
$item.ContentTemplate = $xmlContentTempl.InnerXml

Write-Host "Saving changes..."
Write-Host

$item.put()

Write-Host "Changes were saved!"
Write-Host "New PackageID:"$xmlContentTempl.ContentActionXML.PackageID

}
Write-Host
}

Follow me

2 Comments

AFisher · December 22, 2016 at 17:12

this is not, but the PackageID Object seems to not exist. I have attempted to just pull that info and its just not there. When look at the SMS_AutoDeployment class no PacakageID is listed.. can you help me with what I am missing?

    Thomas Kurth · December 22, 2016 at 18:09

    Which Version of ConfigMgr are you using? Then I can try to reproduce the Problem.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.