Anyone that’s worked on WSUS (Windows Server Update Services) knows that you need to run the server cleanup wizard from time to time. Strangely, however the WSUS GUI does not provide a mechanism to schedule the WSUS server cleanup wizard to run. Fortunately you can easily do this through command line Powershell and the Windows Task Scheduler.
The WsusServerCleanup PowerShell commandlet, supports six functions which are all self explanatory:
- DeclineExpiredUpdates
- DeclineSupersededUpdates
- CleanupObsoleteUpdates
- CleanupObsoleteComputers
- CleanupUnneededContentFiles
- CompressUpdates
The screenshot below shows you the entire process, but we will provide step by step instructions under it:
- Create a file named something like C:\SCRIPTS\WSUS-CLEANUP.PS1 (editable in Notepad if you wish) and enter these lines:
Invoke-WsusServerCleanup -DeclineExpiredUpdates
Invoke-WsusServerCleanup -DeclineSupersededUpdates
Invoke-WsusServerCleanup -CleanupObsoleteUpdates
Invoke-WsusServerCleanup -CleanupObsoleteComputers
Invoke-WsusServerCleanup -CleanupUnneededContentFiles
Invoke-WsusServerCleanup -CompressUpdates
NOTE: Make sure there is a carriage return after the -COMPRESSUPDATES line or the script will not run that last line. - Launch TASK SCHEDULER, right click and
- CREATE NEW TASK
- On the GENERAL tab
- set the NAME to WSUS CLEANUP (or anything else you would prefer)
- Click CHANGE USER OR GROUP button and set it to run with the SYSTEM account
- On the TRIGGERS tab
- Click the NEW button
- Set the schedule you want, most likely DAILY or WEEKLY, running late night or early morning
- On the ACTIONS tab
- In the PROGRAM SCRIPT field, type POWERSHELL
- In the ADD ARGUMENTS filed, type -FILE [path to your PS1 script including the name of the PS1 file] ie. -FILE C:\SCRIPTS\WSUS-CLEANUP.PS1
- Have a nice day with your WSUS Server.
We have seen this simple script clear of hundreds of gigabytes of old and unnecessary windows patches.
0 Comments