This project is read-only.

WSUS Cleanup

Rating:        Based on 13 ratings
Reviewed:  12 reviews
Downloads: 48348
Released: Sep 23, 2008
Updated: Aug 23, 2011 by joseti
Dev status: Beta Help Icon

Recommended Download

Application WsusCleanup v2
application, 9K, uploaded Jun 25, 2009 - 48348 downloads

Release Notes

This tool can automate the cleanup process within WSUS.

The zip contains three files. The exe that performs the cleanup, an optional sql file that can be used to run the WSUS database maintenance script and a small help file. Just extract the files to a single directory and run the exe from a command line. The exe will then look for the sql file and if present run the SQL maintenance script.

Once the tool is complete it will create a log file within the same directory as the tool with the cleanup results but it will also log cleanup results to the application event log.

Create a scheduled task to run this tool monthly.


C:\>WSUSCleanupCL.exe /?
Help menu.

WSUSCleanupCL.exe Server SSL Port Parameter List

server = WSUS server name.
SSL = 't' if using SSL otherwise 'f'.
Port = port number WSUS is listening on. Default is '80' otherwise '8530'.

superseded = cleanup all superseded updates that are no longer needed.
expired = cleanup all expired unapproved updates.
obsolete = cleanup all expired updates regardless of their approval.
compress = cleanup previous revision of updates that are no longer deployable.
computers = cleanup computers that have not contacted the server in over 30 days.
files = cleanup unneeded content files.
DB = runs the database maintenance script (make sure the DB_maint.sql file is present).

all = if all is used all cleanup options above will be run.

Sample commands:
The above command will prompt you to input the server name, SSL configuration and port number WSUS is listening on. This can be run against a local or a remote server and runs ALL cleanup options.

WSUSCleanupCL.exe SomeServer t 8530 all
The above command will connect to SomeServer on port 8530, use SSL and cleanup with all options.

WSUSCleanupCL.exe SomeServer f 80 computers superseded
The above command will connect to SomeServer on port 80, it will not use SSL and cleanup will only run the computers and superseded options (no other cleanup options will run).


If you get a SQL timeout while running the tool I would recommend trying to run the cleanup initially from management studio or use sqlcmd as described here:

The timeout in studio manager or sqlcmd should allow for longer execution time. Once you run it initially and get the database cleaned up the subsequent runs with this tool should work.

Reviews for this release

Expanding on jjdacl's method, you can use this script to manually delete all the obsolete updates rather than just doing them one at a time. DECLARE @var1 INT DECLARE @msg nvarchar(100) CREATE TABLE #results (Col1 INT) INSERT INTO #results(Col1) EXEC spGetObsoleteUpdatesToCleanup DECLARE WC Cursor FOR SELECT Col1 FROM #results OPEN WC FETCH NEXT FROM WC INTO @var1 WHILE (@@FETCH_STATUS > -1) BEGIN SET @msg = 'Deleting ' + CONVERT(varchar(10), @var1) RAISERROR(@msg,0,1) WITH NOWAIT EXEC spDeleteUpdate @localUpdateID=@var1 FETCH NEXT FROM WC INTO @var1 END CLOSE WC DEALLOCATE WC DROP TABLE #results ********* Edit: I tried to format it, but well, I guess this comments section doesn't take any formatting. :-(
by avianwaves on May 2, 2014 at 8:11 PM
For anyone who is getting Timeout Expired with obsolete updates. I have a solution! Use server name : "\\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query" to connect with SQL managment studio. Once connected manually run "exec spGetObsoleteUpdatesToCleanup". This will return a list of obsolete ID's. For each one run "exec spDeleteUpdate @localUpdateID=000000", where 000000 is the ID. For myself I found the first ID in the list took a full 37 minutes to delete and then after that I could run the cleanup through the GUI as per usual.
by jjdacl on Apr 23, 2014 at 8:55 PM
I get a "Timeout expired" error every time. I'd be happy to debug, but NO SOURCE CODE provided.
by jjameson on Mar 21, 2009 at 1:59 PM
The correct connection string for SSMS is: \\.\pipe\mssql$microsoft##ssee\sql\query
by jvierra on Mar 11, 2015 at 1:01 PM
MSFT should just include this in one of their updates!
by nuronce on Oct 10, 2013 at 1:45 PM
Seems to work wonderfully. Per the author's recommendation, I am running it as a Task Sequence. No errors reported, and the WSUS DB seems a little snappier. thanks joseti!
by smahanes on Aug 31, 2011 at 3:55 PM
What are the permissions required for the executing user account, if I want to schedule cleanup task? By the way the tool works great! Thanks
by PeterisE on Jan 19, 2010 at 6:45 AM
Useful tool but I'm also getting the database timeout error on all the servers I try it on. Is it working properly for anyone? Does anyone have a way to can work round this?
by oltconsulting on Jan 16, 2010 at 11:44 AM
I have been using this for quite some time now, in the eventlog for the application I too get the "timeout" error, so it doesn't actually maintain the SQL database. many many subsequent runs still produce the error... is there a fix for this?
by FusionMaster on Dec 14, 2009 at 4:20 AM
This should be part of the product and not an after the fact add-on.
by DLKirchmer on Jan 26, 2009 at 11:31 AM
Great tool! I have been running it for over a month now without a problem and it works great. I actually run it every week since most of my wsus servers have more than 10000 clients.
by tdghia on Nov 24, 2008 at 4:04 PM
I find that while the error is common on first run, subsequent runs work and the tool is very useful :-)
by LesConnor on Oct 30, 2008 at 5:47 PM