If you are using WSUS in your environment, you may want to run a scheduled task to cleanup old updates and compress some of the larger updates to free up space on your server. A good way of doing this is to run a Powershell script which will take care of all your cleanup requirements and as we are using Powershell, we can even get it to send us an email once it is complete with the output information on what the script has managed to clean up.
First of all, you need to decide on what you actually want to do with the script. This includes whether you want to run it manually or add it as a scheduled task or even a System Center Orchestrator Runbook.
For the purposes of this guide, we are going to run the Powershell script with all available options but manually.
For a local WSUS installation, you should use the script below:
As you can see from the script above, we are running the cleanup on all options available to us, i.e. Declined Updates. You can add and remove these as you so wish. The parameters available to you are:
So the above will run manually and then output something like the following within your Powershell window:
But what if you want to receive an email with this information on so that you can stay up to date with what the cleanup is doing, especially if you are running it to a schedule. Using Powershell, you can add additional script to your cleanup script to send an email.