Advertisement
Guest User

Untitled

a guest
May 21st, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $Server = 'localhost'
  2. $port = '8530'
  3.  
  4. Write-Progress -Activity 'Getting WSUS server' -PercentComplete 0
  5. $WSUSserver = Get-WsusServer -Name $server -PortNumber $port
  6.  
  7. Write-Progress -Activity 'Getting unapproved updates, this may take a while...' -PercentComplete 10
  8. $notapprovedupdates = Get-WsusUpdate -UpdateServer $WSUSserver -Approval Unapproved -Status InstalledOrNotApplicableOrNoStatus
  9.  
  10. write-progress -Activity 'Getting Approved updates, this may take a while...' -PercentComplete 20
  11. $approvedupdates = Get-WsusUpdate -UpdateServer $WSUSserver -Approval AnyExceptDeclined -Status InstalledOrNotApplicableOrNoStatus
  12.  
  13. Write-Progress -Activity 'Retrieved update list' -PercentComplete 30
  14.  
  15. $previewupdatelist = $notapprovedupdates | ? {$_.Update.Title -like "*Preview of Monthly*" -or $_.Update.Title -like "*Preview of Quality*"}
  16.  
  17. #$approvedupdatelist = $approvedupdates | ? {$_.Update.Title -like "*Dynamic Cumulative*" -or ($_.Update.Title -like "*Cumulative Update for Windows*" -and $_.Update.IsSuperseded -eq $true)}
  18.  
  19. $approvedupdatelist = $approvedupdates | ? {$_.Update.Title -like "*Dynamic Cumulative*" -or $_.Update.Title -like "*Preview of Monthly*" -or $_.Update.Title -like "*Preview of Quality*"}
  20.  
  21. $oldarchupdatelist = $approvedupdates | ? {$_.Update.Title -like "*ARM64-based*" -or $_.Update.Title -like "*Itanium-based*"}
  22.  
  23. $cuupdatessuperseded = $approvedupdates | ? {($_.Update.IsSuperseded -eq $true -and $_.Update.Title -like "*Microsoft SharePoint*") -or ($_.Update.IsSuperseded -eq $true -and $_.Update.Title -like "*Microsoft Web Apps Server*")}
  24.  
  25. Write-Progress -Activity 'Sorted update list' -PercentComplete 35
  26.  
  27. $total = $previewupdatelist.count + $approvedupdatelist.count + $oldarchupdatelist.count + $cuupdatessuperseded.count
  28.  
  29. $i = 0
  30. foreach ($update in $previewupdatelist)
  31. {
  32.     Write-Progress -Activity 'Declining updates' -Status "$($update.Update.Title)" -PercentComplete (($i/$total) * 100)
  33.     $update.Update.Decline()
  34.     $i++
  35. }
  36.  
  37. foreach ($update in $approvedupdatelist)
  38. {
  39.     Write-Progress -Activity 'Declining updates' -Status "$($update.Update.Title)" -PercentComplete (($i/$total) * 100)
  40.     $update.Update.Decline()
  41.     $i++
  42. }
  43.  
  44. foreach ($update in $cuupdatessuperseded)
  45. {
  46.     Write-Progress -Activity 'Declining updates' -Status "$($update.Update.Title)" -PercentComplete (($i/$total) * 100)
  47.     $update.Update.Decline()
  48.     $i++
  49. }
  50.  
  51.  
  52. foreach ($update in $oldarchupdatelist)
  53. {
  54.     Write-Progress -Activity 'Declining updates' -Status "$($update.Update.Title)" -PercentComplete (($i/$total) * 100)
  55.     $update.Update.Decline()
  56.     $i++
  57. }
  58.  
  59. Write-Host "Total declined preview updates: $($previewupdatelist.count)" -ForegroundColor Yellow
  60. Write-Host "Total declined dynamic and cumulative updates: $($approvedupdatelist.count)" -ForegroundColor Yellow
  61. Write-Host "Total declined updates: $total" -ForegroundColor Yellow
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement