PowerShell – SCCM/SCORCH track software update installations

I recently created a simple PowerShell script to track the software update installation process initiated by SCCM. WMI queries below will check if all available updates is installed.

This kind of logic is useful, if you want to do advanced automation of server patching with Configuration Manager and Orchestrator. And for example replace the @Get Deployment Status activity.” in orchestrator.

#CCM_SoftwareUpdate http://msdn.microsoft.com/en-us/library/jj155451.aspx #Created by Haavard Molland
$Computer = "PPATCH01"
#Count available updates
$updates = @(get-wmiobject -query "SELECT * FROM CCM_SoftwareUpdate" -namespace "ROOT\ccm\ClientSDK" -computer $Computer) | measure
#check for updates beeing installed
$WaitWhileInstalling = @(get-wmiobject -query "SELECT * FROM CCM_SoftwareUpdate WHERE EvaluationState = 6 or EvaluationState = 7" -namespace "ROOT\ccm\ClientSDK" -computer $Computer)
write-host $WaitWhileInstalling

#Wait for SCCM client to complete installation 
If(!$WaitWhileInstalling)  
{   
  $InstalledUpdates = @(get-wmiobject -query "SELECT * FROM CCM_SoftwareUpdate WHERE EvaluationState = 8 or EvaluationState = 9 or EvaluationState = 12" -namespace "ROOT\ccm\ClientSDK" -computer $Computer) | measure
  #Make sure installed updates equals available updates.
  If($InstalledUpdates.Count -eq $updates.count) {$AllUpdatesInstalled = "Yes"}
  write-host $AllUpdatesInstalled 
}

Leave a Reply

Your email address will not be published.