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.
If you have any questions about this guide, please feel free to leave us a message below using our comments system.
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?