This little script will perform a clean up of declined and superceded updates in the WSUS database.  It uses the .Net class "Microsoft.UpdateServices.Administration" assembly, which should be loaded on your WSUS server.  Note that this script will stop the WSUS service twice, but these services will be restarted correctly by the script, and no user action is needed.

 

PowerShell
Edit|Remove
# Performs a cleanup of WSUS. 
# Outputs the results to a text file. 
# Adapted and tested by BigTeddy 
# 3 July 2012 
 
$outFilePath = '.\wsusClean.txt' 
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration"| out-null 
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer(); 
$cleanupScope = new-object Microsoft.UpdateServices.Administration.CleanupScope; 
$cleanupScope.DeclineSupersededUpdates = $true        
$cleanupScope.DeclineExpiredUpdates         = $true 
$cleanupScope.CleanupObsoleteUpdates     = $true 
$cleanupScope.CompressUpdates                  = $true 
#$cleanupScope.CleanupObsoleteComputers = $true 
$cleanupScope.CleanupUnneededContentFiles = $true 
$cleanupManager = $wsus.GetCleanupManager(); 
$cleanupManager.PerformCleanup($cleanupScope| Out-File -FilePath $outFilePath