Created
July 29, 2014 22:48
-
-
Save jacobludriks/9ca9ce61de251a5476f1 to your computer and use it in GitHub Desktop.
wsus-update
This file contains hidden or 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
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 } |
Hey that's a cool script. However I can't get it working, all I get is "HResult: 0 and ResultCode: 2", no updates being installed. Any idea why it doesn't seem to work?
as above, provided aas-is. i am no longer a system administrator and do not deal with wsus anymore.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey that's a cool script. However I can't get it working, all I get is "HResult: 0 and ResultCode: 2", no updates being installed. Any idea why it doesn't seem to work?