Advertisement
anonit

Delete declined updates in WSUS

Oct 14th, 2018
4,526
0
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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement