Windows – SCCM WMI Get Patches that require reboot

powershellsccm-2012windowswindows-server-2008wmi

How can i get all patches that require a reboot before running the install process using WMI and SCCM. So far i have this wmi query that lists all the available patches but none of the properties returned indicate anything about patches being required or not.

function Get-CMMissingUpdate {
param (
$computer = "localhost"
)
    Get-WmiObject -Query "SELECT * FROM CCM_SoftwareUpdate" -Namespace "ROOT\ccm\ClientSDK" -ComputerName $computer
}

Has anyone used anything else to find this information from SCCM 2012 ?

Best Answer

You want to filter on the EvaluationState property of the updates that are returned. There are several types of Evaluation States for pending reboots, they are listed on the technet page for the sccm client sdk. States 8,9, & 10 are for pending reboots. Looking at your function, I would do something like

function Get-CMMissingUpdate {
param (
$computer = "localhost"
)
    Get-WmiObject -Query "SELECT * FROM CCM_SoftwareUpdate WHERE EVALUATIONSTATE = 8 OR EVALUATIONSTATE = 9 OR EVALUATIONSTATE = 10" -Namespace "ROOT\ccm\ClientSDK" -ComputerName $computer
}

If you're going to feed raw syntax instead of using powershell, whatever floats your boat. I don't have any pending sccm updates right now, or time to rig up a test box, but this should get you going.