Skip to content

Instantly share code, notes, and snippets.

@jespernohr
Created January 8, 2017 19:34
Show Gist options
  • Save jespernohr/3b2200986fde35653dbc76a86148711e to your computer and use it in GitHub Desktop.
Save jespernohr/3b2200986fde35653dbc76a86148711e to your computer and use it in GitHub Desktop.
#Scan for available 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
#Install all available updates
$ci = New-CimInstance -Namespace root/Microsoft/Windows/WindowsUpdate -ClassName MSFT_WUOperationsSession
Invoke-CimMethod -InputObject $ci -MethodName ApplyApplicableUpdates
Restart-Computer; exit
#Get a list of 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment