PowerShell for Windows Admins

Nov 17 2017   12:01PM GMT

Windows update change in Server 1709

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Windows Server 2016

When Windows Server 2016 was introduced a very nice CIM class was provided to work with Windows Updates. If you wanted to scan for available updates you could do something like this:

$ci = New-CimInstance -Namespace root/Microsoft/Windows/WindowsUpdate -ClassName MSFT_WUOperationsSession 
$result = $ci | Invoke-CimMethod -MethodName ScanForUpdates -Arguments @{SearchCriteria="IsInstalled=0";OnlineScan=$true}

Unfortunately, if you try this on Windows Server 1709 you’ll get an error:

New-CimInstance : The WS-Management service cannot process the request. The class MSFT_WUOperationsSession does not exist in the root/microsoft/windows/windowsupdate namespace.
 At C:\Program Files\WindowsPowerShell\Modules\WSUSupdates\WSUSupdates.psm1:14 char:9
 + $ci = New-CimInstance -Namespace root/Microsoft/Windows/WindowsUpda ...
 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 + CategoryInfo : ObjectNotFound: (MSFT_WUOperationsSession:CimInstance) [New-CimInstance], CimException
 + FullyQualifiedErrorId : HRESULT 0x80338000,Microsoft.Management.Infrastructure.CimCmdlets.NewCimInstanceCommand
 + PSComputerName : w1709cn01

This change does NOT appear to have been documented.

What you will find is the MSFT_WUOperations CIM class which appears to be a very simplified version of MSFT_WUOperationsSession as it has just 2 static methods.

PS> $class = Get-Cimclass -Namespace root/microsoft/windows/windowsupdate -ClassName MSFT_WUOperations
 PS> $class.CimClassMethods

Name ReturnType Parameters Qualifiers
 ---- ---------- ---------- ----------
ScanForUpdates UInt32 {SearchCriteria, Updates} {implemented, static}
InstallUpdates UInt32 {DownloadOnly, Updates, RebootRequired} {implemented, static}

To scan for available updates on Server 1709 you use it like this:

PS> Invoke-CimMethod -Namespace root/microsoft/windows/windowsupdate -ClassName MSFT_WUOperations -MethodName ScanForUpdates -Arguments @{SearchCriteria="IsInstalled=0"} | select -ExpandProperty Updates

Description : A security issue has been identified in a Microsoft software product that could affect your system.
 You can help protect your system by installing this update from Microsoft. For a complete listing of the issues that are included in this update, see the associated Microsoft Knowledge Base article.
 After you install this update, you may have to restart your system.
KBArticleID :
MsrcSeverity : Critical
RevisionNumber : 201
 Title : Cumulative Update for Windows Server 2016 (1709) for x64-based Systems (KB4043961)
UpdateID : 0d02abc5-41ec-4768-8419-8487fa2e322b
PSComputerName :

To install updates on Server 2016 you’d do something like this

$ci = New-CimInstance -Namespace root/Microsoft/Windows/WindowsUpdate -ClassName MSFT_WUOperationsSession 
 Invoke-CimMethod -InputObject $ci -MethodName ApplyApplicableUpdates

The equivalent for Server 1709 is

PS> $au = Invoke-CimMethod -Namespace root/microsoft/windows/windowsupdate -ClassName MSFT_WUOperations -MethodName ScanForUpdates -Arguments @{SearchCriteria="IsInstalled=0"}

PS> Invoke-CimMethod -Namespace root/microsoft/windows/windowsupdate -ClassName MSFT_WUOperations -MethodName InstallUpdates -Arguments @{Updates = $au.Updates}

RebootRequired ReturnValue PSComputerName
 -------------- ----------- --------------
 True           0

in this case a reboot is required which can be managed with Restart-Computer

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: