Delete declined updates in WSUS

We have all seen poorly maintained WSUS servers.  This script can assist by deleting declined updates.  Combine this with a number of other methods of housekeeping on WSUS servers.

Additionally using the script we can see all the objects returned by the command $wsus.getupdates() | get-member | select name

Name
----
AcceptLicenseAgreement
Approve
ApproveForOptionalInstall
CancelDownload
CreateObjRef
Decline
Equals
ExpirePackage
ExportPackageMetadata
GetChangesFromPreviousRevision
GetHashCode
GetInstallableItems
GetLicenseAgreement
GetLifetimeService
GetRelatedUpdates
GetSummary
GetSummaryForComputerTargetGroup
GetSummaryPerComputerTargetGroup
GetSupportedUpdateLanguages
GetType
GetUpdateApprovals
GetUpdateCategories
GetUpdateClassification
GetUpdateEventHistory
GetUpdateInstallationInfoPerComputerTarget
InitializeLifetimeService
PurgeAssociatedReportingEvents
Refresh
RefreshUpdateApprovals
ResumeDownload
ToString
AdditionalInformationUrls
ArrivalDate
CompanyTitles
CreationDate
DefaultPropertiesLanguage
Description
HasEarlierRevision
HasLicenseAgreement
HasStaleUpdateApprovals
HasSupersededUpdates
Id
InstallationBehavior
IsApproved
IsBeta
IsDeclined
IsEditable
IsLatestRevision
IsSuperseded
IsWsusInfrastructureUpdate
KnowledgebaseArticles
LegacyName
MsrcSeverity
ProductFamilyTitles
ProductTitles
PublicationState
ReleaseNotes
RequiresLicenseAgreementAcceptance
SecurityBulletins
Size
State
Title
UninstallationBehavior
UpdateClassificationTitle
UpdateServer
UpdateSource
UpdateType

2 thoughts on “Delete declined updates in WSUS

  1. BOMCAS CANADA

    Decline update can be remove using a script.

    [reflection.assembly]::LoadWithPartialName(“Microsoft.UpdateServices.Administration”) | Out-Null

    # Run From LocalHost
    $updateServer = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer()

    $updateServer.GetUpdates() | ForEach-Object {
    if (($_.IsSuperseded -eq $true) -and ($_.IsApproved -eq $true)) {
    if ($_.IsDeclined -eq $false) {
    $_.Decline()
    $title = $_.Title
    Write-Host “Declining update: $title”
    }
    }
    }

    $cleanupManager = $updateServer.GetCleanupManager()

    $scope = New-Object “Microsoft.UpdateServices.Administration.CleanupScope”
    $scope.CleanupUnneededContentFiles = $true

    $result = $cleanupManager.PerformCleanup($scope)

    $space = $result.DiskSpaceFreed

    Write-Host “Freed $space bytes.”

    Reply
  2. AnonIT Post author

    HI Bomcas
    Thanks for that. It is interesting. It is slightly different from mine. I do like the report of free space at the end. How does it go on subsequent runs if the initial run doesn’t complete?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *