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 (8)

  1. Christian says:

    Exactly what I was searching for.

    Thank you very much!

  2. Justin says:

    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.

    1. Christian says:

      Perfect completion 😉

  3. JG says:

    Thank you kindly…saved me some serious time today!

  4. Epi says:

    Now that’s what I call Power!

  5. Chris says:

    Mine too… Was looking for something like this for ages 😉

  6. Bikerpete says:

    Thanks, man. That script made my day 🙂

  7. Dagfinn Lunde says:

    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.

Skip to main content