WSUS – Server Clean Up Using Powershell


If you use WSUS then you will be familiar with running Server Cleanup Wizard which is fine but what if you want to use Powershell? well, you can also use that to run the server cleanup on all your WSUS servers.

By using Powershell you have the option to then automate its running using basic windows task scheduler or something a bit more advanced like Orchestrator Runbooks or build it all in to Service Manager.

So, all you need to do is to take the below Powershell script, save it as a .PS1 file and then run as admin on your WSUS server.

$outFilePath = '.wsuscleanup.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 

If you wish to just download the Powershell script then you can do so from here.

It may take time to complete on your server if you have a lot of cleaning up to do so give it time. The script will create a text file in the same location you ran the script from with the completed values for what it has achieved.

Once complete, check your disk space and you should notice a big change in your free space and your updates will be a lot tidier!


If you have any questions about this guide, please feel free to leave us a message below using our comments system.

Free Subscription!Subscribe to our site to receive updates via email!

Enter your email address below and click the Subscribe button to receive email notifications about new and exciting downloads available through our website at

You will also receive notifications about new technical guides, latest news and MSI installer downloads that are available through our blog here at 

We will not spam you and we will not pass on any of your details to anyone else. We tend to post new content once or twice a week.

Join 232 other subscribers

You can unsubscribe any time you like.

About A.J. Armstrong

Founder of TechyGeeksHome and Head Editor for over eight years! IT expert in multiple areas for over 20 years. Sharing experience and knowledge whenever possible! Making IT Happen.

View all posts by A.J. Armstrong