Skip to content

Tag: WSUS

[WSUS] Cleaning up superseded updates

Sadly, the WSUS cleanup wizard neglects to clean up updates that were approved in the past but have been superseded since.

Because these updates tend to use a lot of diskspace, I use a short Powershell script that checks all updates for superseded updates and declines them. After this, the WSUS cleanup wizard can be run again to clear up diskspace.

################################################################
#                                                              #
#  Script for cleaning up superseded updates in WSUS.          #
#                                                              #
#                                                              #
#  -Stefan van Bruggen                                         #
#                                                              #
################################################################

# Change the WSUSserver variable to your server hostname

[String]$WSUSserver = "SERVERNAAM"
[Int32]$port =8530
[Boolean]$SecureConnection = $False

# .NET assembly WSUS inladen

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

# Variable used for counting the total number of declined updates
$count = 0

# Connecting to server

$updateServer = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($WSUSserver,$SecureConnection,$port)

write-host "Connected to WSUS Server" -foregroundcolor "green"

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

# Get the updates and check for superseded updates
$u=$updateServer.GetUpdates($updatescope)

foreach ($u1 in $u )
{
if ($u1.IsSuperseded -eq 'True')
# Declining superseded updates
{
write-host Declined Update : $u1.Title
$u1.Decline()
$count=$count + 1
}
}
write-host Total Declined Updates: $count

exit
Stefan van Bruggen - 2019