anonit

Delete declined updates in WSUS

Oct 14th, 2018
2,123
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This will delete declined updates in a WSUS server.
  2.  
  3. # It can be done in less lines, however there is a chance in poorly maintained WSUS servers of an SQL timeout.
  4. # Doing it in this way allows even partial runs to remove some data, so subsequent runs have more chance of succeeding.
  5.  
  6. [reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
  7. $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
  8. $ListOfUpdates=$wsus.getupdates() | where {$_.isdeclined -eq $TRUE}
  9. $listofupdates | measure | select count
  10. foreach ($UpdateToDelete in $ListOfUpdates) {
  11.     $wsus.DeleteUpdate($UpdateToDelete.Id.UpdateId.ToString()); Write-Host $UpdateToDelete.Title removed }
  12. $ListOfUpdates=$wsus.getupdates() | where {$_.isdeclined -eq $TRUE}
  13. $listofupdates | measure | select count
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×