rj07thomas

Silent install of WSUS updates

Aug 19th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #Defines update criteria: we're interested in "software" (i.e. Windows/ Office, not drivers or anything) that are not yet installed
  2. $newUpdateCriteria = "IsInstalled=0 and Type='Software'"
  3.  
  4. #Search for new updates.
  5. $newUpdateSearcher = New-Object -ComObject Microsoft.Update.Searcher
  6. $newSearchResults = $newUpdateSearcher.Search($newUpdateCriteria)
  7.  
  8. If ($newSearchResults.updates.Count -eq 0)
  9. {
  10. Write-Host "I couldn't find any updates..."
  11. Start-Sleep 5
  12. }
  13. Else
  14. {
  15. #Download updates.
  16. $updateSession = New-Object -ComObject Microsoft.Update.Session #creates a new update session object
  17. $downloader = $updateSession.CreateUpdateDownloader() #creates an object for downloading the updates
  18. $downloader.Updates = $newSearchResults.Updates #assigns the objects found above to the download object
  19. $downloader.Download() #downloads the updates
  20.  
  21. #Install updates
  22. $installer = New-Object -ComObject Microsoft.Update.Installer #creates a new update installer object
  23. $installer.Updates = $newSearchResults.Updates #uses the updates from the initial search to populate what to download
  24. $installUpdates = $Installer.Install() #installs the updates
  25.  
  26. #Reboot if required by updates.
  27.  
  28. If ($installUpdates.RebootRequired -eq $true)
  29. {
  30. Write-Host "This computer needs to be restarted"
  31. }
  32. Else
  33. {
  34. Write-Host "Reboot NOT required!"
  35. Start-Sleep 5
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment