Created
July 19, 2021 23:58
-
-
Save EmmanuelTsouris/34a14d10631cdc68aa0b60c27191ca2e to your computer and use it in GitHub Desktop.
PowerShell for Windows Updates
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
#Scan for available updates | |
function Get-AvailableUpdates { | |
[CmdletBinding()] | |
param() | |
$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 | |
function Install-AvailableUpdates { | |
[CmdletBinding()] | |
param() | |
$ci = New-CimInstance -Namespace root/Microsoft/Windows/WindowsUpdate -ClassName MSFT_WUOperationsSession | |
Invoke-CimMethod -InputObject $ci -MethodName ApplyApplicableUpdates | |
} | |
#list installed updates | |
function Get-InstalledUpdates { | |
[CmdletBinding()] | |
param() | |
$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 | |
} | |
# From <https://richardspowershellblog.wordpress.com/2016/12/22/applying-updates-through-wsus/> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment