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

Thomas Kurth

Principal Workplace Consultant at baseVISION AG
I’m a consultant, trainer and architect formodern workplace and enterprise mobility projects with Microsoft Technologies in the past eight years. I love to push and design the modern workplace based on Windows 10, EM&S and O365 for my customers which is the only answer for the current security threats, agile world and the fast-changing business requirements of my customers. Important for me is to simplify and automate the operational processes, because there are the highest costs.

Enterprise Adminstrator ExpertMCTCMCE
Thomas Kurth
Follow me