Windows: Cleanup files from WSUS which are no longer needed


the content of an WSUS Server crows every month for several GiBytes because WSUS does held all files which has the approval state “install”.

The GUI way to cleanup the WSUS Content folder is to first decline all expired and superseded updates and than run the WSUS Cleanup Wizard.

But you can also use the script way 🙂


# Only needed if the script doesn't run on the WSUS Server
[String]$sWSUSServer = "yourWSUSServer"
[Boolean]$bSecureConnection = $False
[Int32]$iWSUSPort = 8531
            $oWSUSServer = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer()
	    $oWSUSServer = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($sWSUSServer,$bSecureConnection,$iWSUSPort)
catch [Exception]
	write-warning ("Cannot connect to WSUS Server: $sWSUSServer. Error: " + $_)
        exit 1


$oCleanUpScope=new-object Microsoft.UpdateServices.Administration.CleanupScope


Run the script

PS C:\> .\WSUSCleanup.ps1
SupersededUpdatesDeclined : 18
ExpiredUpdatesDeclined    : 0
ObsoleteUpdatesDeleted    : 0
UpdatesCompressed         : 0
ObsoleteComputersDeleted  : 0
DiskSpaceFreed            : 274123310463

Now there is also a Powershell command let which does the same job

PS C:\> Invoke-WsusServerCleanup -CleanupObsoleteUpdates -CleanupUnneededContentFiles -DeclineExpiredUpdates -DeclineSupersededUpdates

If you often got the “Reset Server Node Error” you should do a maintenance task on your WSUS Database. Microsoft offers on SQL script for this issue.

You need the sqlcmd command line tool which is part of MSSQL Management Studio

To start maintenance. Open a cmd shell as Administrator and execute the SQL Script. The database path is for a SQL Express installation. If you use an SQL Server you have to adjust it.

C:\> sqlcmd -S np:\\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query –i D:\temp\WsusDBMaintenance.sql

Or just use the MSSQL Management Studio, connect to the database, open a query, copy the SQL Statement and execute it.


Maintenance Guide
Reindex WSUS DB
Decline-SupersededUpdatesWithExclusionPeriod.ps1 runs in timeout or error 401
WSUS Cleaning wizard runs in timeout

Advertisment to support

WSUS Cleanup

Script to cleanup unused content from WSUS

Platforms:Windows 98, Windows 2000, Windows XP, Windows Vista, Windows 7
Category:Powershell Scripts
Date:July 23, 2017
1.5 KiB

2 thoughts on “Windows: Cleanup files from WSUS which are no longer needed”

    1. Hi Daniel,

      have tried it on the same machine the wsus runs?

      Have you definied a system proxy?
      netsh winhttp show proxy


Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.