Last active
January 11, 2018 19:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 I just tested it on Windows 10 version 10.0.10586.0 and it works fine. Any specific errors?
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
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?