Skip to content

Instantly share code, notes, and snippets.

@aaronwalker
Forked from jacobludriks/wsus-update.ps1
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save aaronwalker/698922e7ec3db4c62c27 to your computer and use it in GitHub Desktop.

Select an option

Save aaronwalker/698922e7ec3db4c62c27 to your computer and use it in GitHub Desktop.
Function WSUSUpdate {
$Criteria = "IsInstalled=0 and Type='Software'"
$Searcher = New-Object -ComObject Microsoft.Update.Searcher
try {
$SearchResult = $Searcher.Search($Criteria).Updates
if ($SearchResult.Count -eq 0) {
Write-Output "There are no applicable updates."
exit
}
else {
$Session = New-Object -ComObject Microsoft.Update.Session
$Downloader = $Session.CreateUpdateDownloader()
$Downloader.Updates = $SearchResult
$Downloader.Download()
$Installer = New-Object -ComObject Microsoft.Update.Installer
$Installer.Updates = $SearchResult
$Result = $Installer.Install()
}
}
catch {
Write-Output "There are no applicable updates."
}
}
WSUSUpdate
If ($Result.rebootRequired) { Restart-Computer }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment