Microsoft Windows – Automate Disk Cleanup

Release date: April 19th 2020

Welcome to my Microsoft Tips & Tricks section. Everyone knows that patching your Windows Servers are important. In my lab I have automated the downloading, installing and restarts of my Windows servers. But cleaning up old updates and logs etc. have been done manually up until now. I have used the Disk Cleanup utility periodically and manually cleaned up the disks. This is tiresome and boring. As this is a lab-environment, I want to automate as much as possible to be able to spend time labbing exiting setups instead of doing maintenance. Therefore I have made this little session describing how I did this.

The first thing to do is to define what the Disk Cleanup utility should clean up. I launch an administrative command prompt and run the following command: cleanmgr.exe /sageset:1

ScheduleDiskCleanup-01

 

I check the items I want Disk Cleanup to automatically clean

ScheduleDiskCleanup-02

ScheduleDiskCleanup-03

 

Next I create a Scheduled task that runs Disk Cleanup weekly

ScheduleDiskCleanup-04

ScheduleDiskCleanup-05

ScheduleDiskCleanup-06

ScheduleDiskCleanup-07

ScheduleDiskCleanup-08

ScheduleDiskCleanup-09

ScheduleDiskCleanup-10

 

When I have my new task created, I do a test run of this task. I can now export this task and import it on my other servers, but I also have to define what items the Disk Cleanup utility cleans up using the command I describe to begin with in this post.

 

Microsoft Tips & Tricks section

Disclaimer: Every tips/tricks/posting I have published here, is tried and tested in different it-solutions. It is not guaranteed to work everywhere, but is meant as a tip for other users out there. Remember, Google is your friend and don’t be afraid to steal with pride! Feel free to comment below as needed.