Tip: Use Some (Relatively) Unknown Command-Line Switches for Disk Cleanup

Follow Our Daily Tips


Disk Cleanup offers some cool command-line switches that are documented only in a pair of obscure Knowledge Base articles. Through the use of these switches, you can save your preferences and rerun the cleanup process automatically using those settings. To do so, you need to use the following switches with Cleanmgr.exe:

/Sageset:n Opens a dialog box that allows you to select Disk Cleanup options, creates a registry key that corresponds to the number you entered, and then saves your settings in that key. Enter a number from 0 through 65535 in place of n.

/Sagerun:n Retrieves the saved settings for the number you enter in place of n and then runs Disk Cleanup without requiring any interaction on your part.

To use these switches, follow these steps:

1. Open a Command Prompt window and type the command cleanmgr /sageset:200. (The number after the colon is completely arbitrary; you can choose any other number from 0 through 65535.) Note that you must supply credentials from a member of the Administrators group to begin this task.

2. In the Disk Cleanup Settings dialog box, choose the options you want to apply whenever you use these settings.

3. Click OK to save your changes in the registry.

4. Open Task Scheduler from Control Panel, and start the Create Basic Task wizard. Follow the wizard’s prompts to name the task, and schedule it to run at regular intervals. When prompted to select the program you want Windows to run, type cleanmgr.exe in the Program/Script box and type /sagerun:200 in the Add Arguments box.

5. Repeat steps 1–4 for other Disk Cleanup options that you want to automate.

From the Microsoft Press book Windows Server 2008 Administrator’s Pocket Consultant, Second Edition by William R. Stanek.

Looking for More Tips?

For more tips on Microsoft products and technologies, visit the TechNet Tips library.