PowerShell Script to decline all Superseded Updates in WSUS

At time troubleshooting on cases we had to decline updates which are superseded  from the WSUS and hence help to make sure that the no of updates the update agent scan is reduced.

=========================================================

#Change server name and port number and $True if it is on SSL

[String]$updateServer1 = "CMCAS"

[Boolean]$useSecureConnection = $False

[Int32]$portNumber =8530

# Load .NET assembly

[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")

$count = 0

# Connect to WSUS Server

$updateServer = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($updateServer1,$useSecureConnection,$portNumber)

write-host "<<<Connected sucessfully >>>" -foregroundcolor "yellow"

$updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope

$u=$updateServer.GetUpdates($updatescope )

foreach ($u1 in $u )

{

if ($u1.IsSuperseded -eq 'True')

{

write-host Decline Update : $u1.Title

$u1.Decline()

$count=$count + 1

}

}

write-host Total Declined Updates: $count

trap

{

write-host "Error Occurred"

write-host "Exception Message: "

write-host $_.Exception.Message

write-host $_.Exception.StackTrace

exit

}

# EOF

==========================================================

This posting /Script is provided "AS IS" with no warranties and confers no rights

Comments

  • Anonymous
    June 12, 2015
    Works great to clean up a fresh server before approving the "real" updates. I managed to reduce the updates from 80 GB to 16 only by declining not needed updates with this script.
  • Anonymous
    September 22, 2015
    Thanks, man. That script made my day :-)
  • Anonymous
    September 29, 2015
    Mine too... Was looking for something like this for ages ;)
  • Anonymous
    November 03, 2015
    Now that's what I call Power!
  • Anonymous
    January 25, 2016
    Thank you kindly...saved me some serious time today!
  • Anonymous
    May 31, 2016
    Nice, thanks. If you change the 'if' statement to if (($u1.IsSuperseded -eq 'True') -and ($u1.IsDeclined -ne 'True'))and run it as a daily scheduled task, it'll only decline that which is newly-superseded and not already declined.
    • Anonymous
      September 14, 2016
      Perfect completion ;)
  • Anonymous
    September 14, 2016
    Exactly what I was searching for.Thank you very much!