You must first run cleanmgr /sageset:1 to configure which file types to delete. That setting is then reused by /sagerun:1 .
Once your settings are saved, you can trigger the cleanup without any further user interaction. cleanmgr /sagerun:1 disk cleanup command line
Use this switch to choose exactly which file categories you want to clean (e.g., Temporary Files, Recycle Bin, Windows Update Cleanup). cleanmgr /sageset:1 You must first run cleanmgr /sageset:1 to configure
To clean up the drive (auto-select default file types): cleanmgr /sagerun:1 Use this switch to choose exactly
Finally, the command line facilitates scalability and remote management. In a corporate environment, an IT professional cannot physically sit at hundreds of workstations to run the Disk Cleanup wizard. However, by utilizing command-line tools invoked through PowerShell or scheduled tasks, they can push a single cleanup configuration to an entire fleet of machines. This standardization ensures that every computer operates with the same efficiency standards, reducing helpdesk tickets related to low disk space and maintaining optimal system performance across the board.
The primary tool for command-line disk cleanup is the same executable used by the GUI, cleanmgr.exe , but launched with specific flags that alter its behavior. The most fundamental of these is the /sageset and /sagerun parameter pair. Unlike the standard GUI, which requires a user to manually check boxes every time it runs, the command line allows for the creation of persistent configuration profiles. By running cleanmgr /sageset:n (where n is a number), an administrator opens the interface once to select specific categories for deletion, such as temporary internet files, downloaded program files, or thumbnails. These preferences are then saved to the registry. Subsequently, running cleanmgr /sagerun:n executes the cleanup instantly using those saved preferences, bypassing the need for user interaction. This feature is invaluable for creating unattended maintenance scripts that run during off-hours.