Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $Server = 'localhost'
- $port = '8530'
- Write-Progress -Activity 'Getting WSUS server' -PercentComplete 0
- $WSUSserver = Get-WsusServer -Name $server -PortNumber $port
- Write-Progress -Activity 'Getting unapproved updates, this may take a while...' -PercentComplete 10
- $notapprovedupdates = Get-WsusUpdate -UpdateServer $WSUSserver -Approval Unapproved -Status InstalledOrNotApplicableOrNoStatus
- write-progress -Activity 'Getting Approved updates, this may take a while...' -PercentComplete 20
- $approvedupdates = Get-WsusUpdate -UpdateServer $WSUSserver -Approval AnyExceptDeclined -Status InstalledOrNotApplicableOrNoStatus
- Write-Progress -Activity 'Retrieved update list' -PercentComplete 30
- $previewupdatelist = $notapprovedupdates | ? {$_.Update.Title -like "*Preview of Monthly*" -or $_.Update.Title -like "*Preview of Quality*"}
- #$approvedupdatelist = $approvedupdates | ? {$_.Update.Title -like "*Dynamic Cumulative*" -or ($_.Update.Title -like "*Cumulative Update for Windows*" -and $_.Update.IsSuperseded -eq $true)}
- $approvedupdatelist = $approvedupdates | ? {$_.Update.Title -like "*Dynamic Cumulative*" -or $_.Update.Title -like "*Preview of Monthly*" -or $_.Update.Title -like "*Preview of Quality*"}
- $oldarchupdatelist = $approvedupdates | ? {$_.Update.Title -like "*ARM64-based*" -or $_.Update.Title -like "*Itanium-based*"}
- $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*")}
- Write-Progress -Activity 'Sorted update list' -PercentComplete 35
- $total = $previewupdatelist.count + $approvedupdatelist.count + $oldarchupdatelist.count + $cuupdatessuperseded.count
- $i = 0
- foreach ($update in $previewupdatelist)
- {
- Write-Progress -Activity 'Declining updates' -Status "$($update.Update.Title)" -PercentComplete (($i/$total) * 100)
- $update.Update.Decline()
- $i++
- }
- foreach ($update in $approvedupdatelist)
- {
- Write-Progress -Activity 'Declining updates' -Status "$($update.Update.Title)" -PercentComplete (($i/$total) * 100)
- $update.Update.Decline()
- $i++
- }
- foreach ($update in $cuupdatessuperseded)
- {
- Write-Progress -Activity 'Declining updates' -Status "$($update.Update.Title)" -PercentComplete (($i/$total) * 100)
- $update.Update.Decline()
- $i++
- }
- foreach ($update in $oldarchupdatelist)
- {
- Write-Progress -Activity 'Declining updates' -Status "$($update.Update.Title)" -PercentComplete (($i/$total) * 100)
- $update.Update.Decline()
- $i++
- }
- Write-Host "Total declined preview updates: $($previewupdatelist.count)" -ForegroundColor Yellow
- Write-Host "Total declined dynamic and cumulative updates: $($approvedupdatelist.count)" -ForegroundColor Yellow
- Write-Host "Total declined updates: $total" -ForegroundColor Yellow
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement