Automatically free up hard drive space with the Disk Cleanup tool on Windows 10

Disk Cleanup is a maintenance tool that has been part of Windows for a long time, and it allows you to reclaim hard drive space to make room for more of your valuable content. With it you can quickly find and get rid of temporary and system files, such as previous Windows installation files and updates, which otherwise would be nearly impossible for regular users to find and remove — and those files might be taking up gigabytes worth of space!

However, even on Windows 10, Disk Cleanup remains a tool that you have to run manually. What you probably may not know is that you can configure the tool to run automatically to delete certain files from your computer.

In this Windows 10 guide, we'll walk you through the process to configure the Disk Cleanup tool and use the Task Scheduler to remove unnecessary files from your computer making space for new content.

How to automate Disk Cleanup on your PC

  1. Use the Windows key + X keyboard shortcut to open the Power User menu and select Command Prompt (Admin).
  2. Type the following command and press Enter:cleanmgr /sageset:11In this command, we're using the switch /sagest:n to open the Disk Cleanup settings and at the same time create a registry key that will store the settings you choose. The n number, which is also stored in the registry, indicates the settings you want to use with the tool.The number can be anything from 0 to 65535, and it's basically like a filename that points to all the specific settings you want to use. This way, you can set different numbers to run the tool with different settings at different times.

  1. Once the Disk Cleanup Settings opens, check the items you want the tool to remove automatically from your system from the extensive list. Some of the files you can clean up include:
    • Windows Update Cleanup
    • Downloaded Program Files
    • Temporary Internet Files
    • Temporary files
    • System error memory dump files
    • Files discarded by Windows upgrade
    • Windows ESD installation files
    • Previous Windows installations
    • Recycle Bin
    • Temporary Windows installation files
  2. Click the OK button to save and store the settings in the registry.

  1. Open Start, do a search for Task Scheduler and click the result to open the utility.
  2. Right-click Task Scheduler Library, click New Folder and name the folder something descriptive like User Defined Tasks.
  3. Right-click the newly created folder and click Create Basic Task.

  1. Name the task, add a description you like, and click Next.

  1. Select when you want the task to run and click Next. These options are very flexible as you can set different times, in addition to set specific events to trigger the task. For the purpose of this guide, we'll be choosing Monthly.

  1. Select the date and time, and click Next.

  1. On Action, select Start a program and click Next.

  1. Type the path to open the Disk Cleanup tool: C:\Windows\system32\cleanmgr.exe and include the argument /sagerun:11. (Remember to change the number 11 to the number you that you chose in step 2 to use the settings you have configured.)
  2. Click Next.

  1. On the Summary page, click Finish to complete the task.

After completing the task, the Disk Cleanup tool will run at the time you specified, deleting all unnecessary files from your computer. If for any reason, you need to change the current settings for the task, open the Task Scheduler, open the folder you created, double-click task, and update the configuration.

How to run Disk Cleanup out of its schedule

You can use the following steps, in the case, you want to run Disk Cleanup before the specified schedule:

  1. Use the Windows key + X keyboard shortcut to open the Power User menu and select Command Prompt (Admin).
  2. Type the following command and press Enter:C:\Windows\system32\cleanmgr.exe /sagerun:11Remember to change 11 to the number you have chosen. After running the command, the Disk Cleanup tool will open and run immediately, removing all the files you have configured on the tool.

How to modify Disk Cleanup settings

If you want to add or remove items you want Disk Cleanup to delete automatically, then use these steps:

  1. Use the Windows key + X keyboard shortcut to open the Power User menu and select Command Prompt (Admin).
  2. Type the following command and press Enter:cleanmgr /sageset:11Remember to change 11 to the number you have chosen to store the settings.
  3. As you execute the previous command, you will notice that the Disk Cleanup tool will open with all the settings you have previously configured. Now simply modify the list by checking the new items and removing the ones you don't want.
  4. Click OK to complete the task.

Disk Cleanup is a great tool that continues to come included with Windows 10, and it can help you to reclaim space on your hard drive. In the latest version of the operating system, it's also a great way for users in the Windows Insider Program to check periodically and delete previous installations of the operating system, which are known to take up several gigabytes after a new build of Windows 10 is installed.

Important: Deleting previous installation files will prevent you from rolling back to the previous version of the operating system.

Furthermore, you can also use this technique to help family and friends to keep their computers free of clutter by automating Disk Cleanup to remove unnecessary files, such as those in the Recycle Bin, common temporary files, old Windows updates, and other files.

Finally, remember that even though we're focusing these steps for Windows 10 PCs, you can also use the same concept to clean up files and reclaim space on Windows 8.1, Windows 7, and other versions of the operating system.

Do you usually remember to clean up unnecessary files from your Windows 10 PC? What kind of utility do you use? Tell us in the comments below.

More Windows 10 resources

For more help articles, coverage, and answers on Windows 10, you can visit the following resources:

Mauro Huculak

Mauro Huculak has been a Windows How-To Expert contributor for for nearly a decade and has over 15 years of experience writing comprehensive guides. He also has an IT background and has achieved different professional certifications from Microsoft, Cisco, VMware, and CompTIA. He has been recognized as a Microsoft MVP for many years.