AIM

ConfigMgr DCM/Compliance – Check if windows update requires a reboot

This is another post in the series of ConfigMgr Configuration Items. This one is used to check if windows update has a pending reboot.

A common problem with patch management is that updates are installed but it’s up to the user to reboot.

With this configuration item you can measure how many computers has installed windows updates but has not yet rebooted.

Use the following powershell script and configure the compliance rule to “The value returned by the script equals Compliant!”
—Script begins below this—

# // ***************************************************
# // ********************** Header **********************
# //
# // Solution: Check if windows update has a pending reboot
# // URL: https://www.addlevel.se
# //
# // Filename: CheckWindowsUpdateReboot.ps1
# // Version: 1.0.00.002
# //
# // Purpose: –
# //
# // Usage: For ConfigMgr compliance usage. Should return “Compliant!” if compliant.
# //
# //
# // History:
# // Jonas Lagerström 2012-10-22 Created initial script.
# //
# //
# // Disclamer:
# // This script is provided “AS IS” with no warranties, confers no rights and
# // is not supported by the authors.
# //
# // **************** End Header ******************
# // ***************************************************

Try
{
$WinUpdate = New-Object -ComObject Microsoft.Update.SystemInfo
$ComputerName=$env:computername

IF ($WinUpdate.RebootRequired -eq $false)
{
write-host “Compliant!”
}

else
{
$BootTime = (Get-WmiObject -Class Win32_OperatingSystem -computername $ComputerName).LastBootUpTime
$Uptime = (Get-Date) – [System.Management.ManagementDateTimeconverter]::ToDateTime($BootTime)
Write-Host “Reboot required – Last reboot was” $Uptime.days “days” $Uptime.hours “hours” $Uptime.minutes “minutes” $Uptime.seconds “seconds ago”
}

}

Catch
{
Write-Warning “Failed to get windows update reboot status”
Write-Error $_
}

—Script ends above this—

Usual warnings apply, please test all scripts before running them in a production environment!

Best regards,

Jonas Lagerström

Posted in Blog, Configuration Manager.