Installing Updates from Configuration Manager with PowerShell

Profile picture for user PaulW

If you want to trigger an update available from CM in Software Center via a PowerShell script, you can use something like the following:

$UpdateID = 'Site_1EED8E47-D4D8-4823-883C-4FFE753FA233/SUM_0af47e05-17cb-4756-8610-09ce486df1ba'
$Instance = @(Get-CimInstance -Namespace ROOT\ccm\ClientSDK -ClassName CCM_SoftwareUpdate -Filter "UpdateID like '$UpdateID'")
If ($Instance) {
	Invoke-CimMethod -Namespace ROOT\ccm\ClientSDK -ClassName CCM_SoftwareUpdatesManager -MethodName InstallUpdates -Arguments @{CCMUpdates = [ciminstance[]]$Instance}

# And then this to get details on the Progress
start-Sleep -seconds 60
$Instance = @(Get-CimInstance -Namespace ROOT\ccm\ClientSDK -ClassName CCM_SoftwareUpdate -Filter "UpdateID like '$UpdateID'")
write-host "Current Update State: $($Instance.EvaluationState)"
write-host "Current Update Progress: $($Instance.PercentComplete)"

Properties of the CCM_SoftwareUpdate class are laid out here:

EvaluationState property actually has 24 states.  But, most of the time, we'll be interested in only the bolded below.

ID State Name
0 ciJobStateNone
1 ciJobStateAvailable
2 ciJobStateSubmitted
3 ciJobStateDetecting
4 ciJobStatePreDownload
5 ciJobStateDownloading
6 ciJobStateWaitInstall
7 ciJobStateInstalling
8 ciJobStatePendingSoftReboot
9 ciJobStatePendingHardReboot
10 ciJobStateWaitReboot
11 ciJobStateVerifying
12 ciJobStateInstallComplete
13 ciJobStateError
14 ciJobStateWaitServiceWindow
15 ciJobStateWaitUserLogon
16 ciJobStateWaitUserLogoff
17 ciJobStateWaitJobUserLogon
18 ciJobStateWaitUserReconnect
19 ciJobStatePendingUserLogoff
20 ciJobStatePendingUpdate
21 ciJobStateWaitingRetry
22 ciJobStateWaitPresModeOff
23 ciJobStateWaitForOrchestration

In State 7, ciJobStateInstalling, the PercentComplete property populates and becomes useful.

In State 13, ciJobStateError, the ErrorCode property (usually) populates and becomes useful.

Related Technology

Add new comment

The content of this field is kept private and will not be shown publicly.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.