Skip to content

Instantly share code, notes, and snippets.

@EmmanuelTsouris
Last active January 11, 2018 19:04
Show Gist options
  • Save EmmanuelTsouris/da46856be9e5c14941124be970271155 to your computer and use it in GitHub Desktop.
Save EmmanuelTsouris/da46856be9e5c14941124be970271155 to your computer and use it in GitHub Desktop.
Windows Server 2016 and Nano Server CimMethods for Windows Updates using MSFT_WUOperationsSession
Write-Host "Installed Updates"
$ci = New-CimInstance -Namespace root/Microsoft/Windows/WindowsUpdate -ClassName MSFT_WUOperationsSession
$result = $ci | Invoke-CimMethod -MethodName ScanForUpdates -Arguments @{SearchCriteria="IsInstalled=1";OnlineScan=$true}
$result.Updates
Write-Host "Missing Updates"
$ci = New-CimInstance -Namespace root/Microsoft/Windows/WindowsUpdate -ClassName MSFT_WUOperationsSession 
$result = $ci | Invoke-CimMethod -MethodName ScanForUpdates -Arguments @{SearchCriteria="IsInstalled=0";OnlineScan=$true}
$result.Updates
Write-Host "Installing the Updates"
$ci = New-CimInstance -Namespace root/Microsoft/Windows/WindowsUpdate -ClassName MSFT_WUOperationsSession
Invoke-CimMethod -InputObject $ci -MethodName ApplyApplicableUpdates
#Restart-Computer; exit
@NonSecwitter
Copy link

I was testing this on Windows 10 today, but I can't get it to run on desktop OS. Am I missing something, or do you know if there are limitations?

@EmmanuelTsouris
Copy link
Author

EmmanuelTsouris commented May 24, 2017

@NonSecwitter I just tested it on Windows 10 version 10.0.10586.0 and it works fine. Any specific errors?

@jberezanski
Copy link

It seems there have been changes in recent Windows 10 / Windows Server versions and the MSFT_WUOperationsSession class has been replaced with a static MSFT_WUOperations class (http://itknowledgeexchange.techtarget.com/powershell/windows-update-change-server-1709/). On my Windows 10 1709 (10.0.16299.192) the following command works:

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

(however, it currently returns 0 updates, so I can't test downloading/installing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment