Cleanup WSUS

I’ve never had to perform a WSUS cleanup for years, shame on me 😉

Lawrence Garvin, who answers all the WSUS maintenance related questions on the mailing list made me change my mind recently.

His post explains what are the benefits of performing maintenance tasks on a regular basis:


Having WSUS built-in Windows 2012 R2 servers makes it very easy with PowerShell 😀

Here’s what I do a few days later, after performing my usual Patch Tuesday duties (~synchronize and approve required updates):

  • Step 1: Decline all updates that have been superseded and not approved
$UpdateScope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$allupdates = (Get-WsusServer).GetUpdates($UpdateScope)
$allupdates | Where {
 ($_.IsSuperseded) -and
 -not($_.isApproved) -and
} | ForEach-Object -Process {            
  • Step 2: Use the built-in cmdlet to perform the maintenance and display results
$cleanupResults = Get-WsusServer | 
Invoke-WsusServerCleanup -CleanupObsoleteUpdates `
-CleanupUnneededContentFiles -CompressUpdates `
-DeclineExpiredUpdates -DeclineSupersededUpdates:$false -Verbose

'Diskspace Freed: {0:N2} GB' -f (
(($cleanupResults | sls -Pattern "^DiskSpace").Line -split ":")[1] / 1GB 

To summarize, I’ve now:

  • Updates being displayed faster in the console, when I select ‘Any Except Declined’
  • Compressed updates (less to transport over the wire)
  • Made some free space on the server (~ 1,5 GB in my case, the first time)
  • A cleanup maintenance task performing faster next month

PowerShell and WSUS, that rocks! – no doubt 😎 and a huge thanks to Lawrence Garvin for his excellent input on this subject 😀


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.