Scenario: You use Microsoft System Center 2012 Configuration Manager to receive updates for Windows. Once your updates are approved for installation, you can use the following script to perform a manual install. Once the manual install is kicked off from a remote machine, you can use additional PowerShell commands to determine the statuses for each update.
Here is a copy of the script we are using that is located on each one of our servers. Reference to the script found here.
InstallUpdates.PS1
$MissingUpdates = Get-WmiObject -Class CCM_SoftwareUpdate -Filter ComplianceState=0 -Namespace rootCCMClientSDK $MissingUpdatesReformatted = @($MissingUpdates | ForEach-Object {if($_.ComplianceState -eq 0){[WMI]$_.__PATH}}) $InstallReturn = Invoke-WmiMethod -Class CCM_SoftwareUpdatesManager -Name InstallUpdates -ArgumentList (,$MissingUpdatesReformatted) -Namespace rootccmclientsdk $objCurrentPSProcess = [System.Diagnostics.Process]::GetCurrentProcess(); Stop-Process -Id $objCurrentPSProcess.ID;
To kick this script off remotely on your servers, you can use a similar PowerShell command such as:
Invoke-Command { powershell.exe -executionpolicy unrestricted C:updatesInstallUpdates.ps1} -ComputerName Win2012Svr1
OR, to run against multiple servers at once… Lets Loop It!
$Servers = Get-ExchangeServer Win2012Svr*
$Servers | %{Invoke-Command { powershell.exe -executionpolicy unrestricted C:updatesInstallUpdates.ps1} -ComputerName $_}
Instead of using Software Center to check the status of your updates via an RDP session to multiple servers, lets use PowerShell again to invoke a command that will return the EvaluationState for each update:
Invoke-Command -computername Win2012Svr1 -scriptblock {Get-WmiObject -Class CCM_SoftwareUpdate -Namespace rootCCMC
lientSDK | Group EvaluationState}
OR against multiple servers, Lets loop it again!
$Servers = Get-ExchangeServer Win2012Svr*
$Servers | %{Invoke-Command -computername $_ -scriptblock {Get-WmiObject -Class CCM_SoftwareUpdate -Namespace rootCCMClientSDK | Group EvaluationState}}
Below is what we determined each status represents. Obviously there are some numerical codes missing, but these are the normal status codes we occasionally see:
0 = Not Started
5 = Downloading
6 = Waiting to Install
7 = Installing
8 = Requires Restart
13 = Failed
To restart the computers remotely, you can issue the following PowerShell Commands:
Restart-Computer Win2012Svr1 -force
or multiple servers:
$Servers = Get-ExchangeServer Win2012Svr*
$Servers | Restart-computer -force
Happy updating!