Easy Disk Cleanup with Scheduled Tasks

Even though hard drives are larger and cheaper than ever, we still need to clean up our PC. Apart from the files we create, Windows creates others such as temp files, error files, and setup files with limited value. One way to remove these space-hogging files is to create a Windows 10 scheduled task with the disk cleanup tool to delete files regularly. Once you understand scheduled tasks, you’ll start automating other maintenance items.

info icon This tutorial was originally written for Windows 7. It has been updated to reflect Windows 10 task scheduler.

There are many ways to clean up your drive. Perhaps, the best-known method is to highlight files and hit delete or drag them to the Recycle bin. This process works well for files we recognize or files that don’t need to be securely erased. Behind the scenes, there are countless files created when you install software and browse the web. You don’t consciously think about these files since you never gave them a name. They are ancillary stuff occupying space and possibly slowing your computer.

Defining the Disk Cleanup with Sagesets

Microsoft added a disk cleanup tool to various versions of the operating system. The tool is buried under several layers, but you can get to it from Start | All Programs | Accessories | System Tools. This gem of a program is called cleanmgr.exe.

You can run the program using the path mentioned above, but it requires that you select a drive and settings each time you use it. A more efficient way is to create a sageset that maintains your settings. You might think of a sageset like a profile written to the Windows registry. Rather than providing a profile name, Windows uses a number. You can have up to 65,535 sagesets.

To Create a Windows Disk Cleanup Sageset

  1. In the Search bar next to your Windows key, type cmd.
searching for cmd
  1. Select Command Prompt from the results.
selecting Command PromptPin
  1. In the Command Prompt window, type cleanmgr /sageset:1
setting cleanmgrPin
  1. Press Enter.
  2. In the Disk Cleanup Settings dialog, check the delete options you prefer.
setting disk cleanup optionsPin
  1. Click OK.

Since you can have many sagesets, you could create one set to run daily and another to run weekly based on your usage. You just assign a different number and settings such as /sageset:2

warning icon. One cautionary note is I wouldn’t delete Office Setup Files unless you’re short on disk space.

Automate Disk Cleanup with Windows 10 Scheduled Tasks

Once you’ve created your sageset, which tells Windows which files to delete during an automatic disk cleanup, you need to define when this process should run. This is done using the Task Scheduler tool.

The tool is another one that is rarely used. It allows you to run a program on a predefined basis, whether daily or a one-time basis. It works with many programs and not just cleanmgr.exe.

For our purposes, we will use it to run cleanmgr.exe with our defined sageset. This is done using the advanced features and the sagerun command.

To set a Scheduled Task with Sagerun

  1. In the Search bar next to your Windows key windows icon, type Scheduled tasks.
  2. Select Scheduled Task from the results. It will show with Control Panel underneath.
scheduled tasks appPin

Alternatively, you could type Task Scheduler.

  1. Click Create Basic Task… to start the Scheduled Task Wizard.
adding a basic taskPin
  1. Provide a name for your task.
  2. Enter some description about the task. Click Next.
  3. Set your time trigger using the radio button selections. Click Next.
  4. Add in your additional time options based on your previous section. Click Next.
  5. For the Action option, select Start a program.
  6. Click Next.
  7. You will not see cleanmgr.exe listed so you need to click Browse.
click browse to find programPin
  1. Navigate to the folder containing your program. In our case, it’s in the Windows > System 32 folder.
  2. Type cleanmgr.exe in the File name textbox and click Open.
finding cleanmgrPin
  1. Type /sagerun:1 in the Add arguments (optional) textbox.
  2. Click Next.
  3. A task summary will appear with your information about the scheduled task.
scheduled task summaryPin
  1. Click Finish.

When the designated time occurs, your custom cleanmgr program should start. If it doesn’t, open Scheduled Tasks and see if anything shows in the Status column.

Usually, when I create a scheduled task, I test it by using a time that is 5 minutes out and watch the results. If anything is wrong such as password errors, I can correct it sooner than later. Once the task runs to my liking, I edit the times by right-clicking and selecting properties from the Scheduled Tasks.

After you get the gist of how these tools work, you’ll probably set up scheduled tasks for other items besides disk cleanup. Although this trick may not stop you from needing another hard drive, it can delay that purchase and buy you some extra time.

If you have an older version of Microsoft Windows, you can follow this article for help.