Readers help support Windows Report. We may get a commission if you buy through our links.
Read our disclosure page to find out how can you help Windows Report sustain the editorial team Read more
Keeping your Windows system running smoothly often involves regular disk cleanup. Automating this process can save you time and ensure your system remains clutter-free without manual intervention. Here’s how you can achieve silent disk cleanup using command line methods.
How do I run Disk Cleanup command line for silent execution?
1. Using the /VERYLOWDISK Switch
- Press the Windows key, type cmd, then click on Run as administrator from the search results.
- Enter the command:
cleanmgr.exe /VERYLOWDISK
- This command will clean up all files automatically and show a dialog with the amount of freed-up space, but does not require user interaction during the cleaning process.
This method helps clean up unnecessary files effectively without needing manual confirmation, making it ideal for automated scripts.
2. Using /SAGESET and /SAGERUN for Presets
- Create a Preset for Disk Cleanup:
- Open Command Prompt as an administrator.
- Execute
cleanmgr.exe /SAGESET:1
- Select all desired cleanup options in the dialog box.
- Click OK to save the preset settings.
- Run the Saved Preset:
- Use the following command to run the previously saved settings automatically:
cleanmgr.exe /SAGERUN:1
- Use the following command to run the previously saved settings automatically:
This technique allows you to configure and reuse cleanup settings without any manual intervention on future runs.
3. Combining /VERYLOWDISK in a Script
- Press Windows key, type Notepad, and open it.
- Type or paste the following script:
@echo off set rootkey=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches for /f "tokens=*" %%K in ('reg query %rootkey%') do >NUL REG add "%%K" /v StateFlags0000 /t REG_DWORD /d 2 /f cleanmgr /sagerun:0
- Save the file with a .bat extension, for example, cleanup.bat.
- Now, right-click the batch file and select Run as administrator.
This script automatically sets all cleanup options and runs the Disk Cleanup tool without any user interaction, providing a fully automated solution.
4. Scheduling Disk Cleanup with Task Scheduler
- Press the Windows key, type Task Scheduler, and open it.
- Create a New Task:
- In the Actions pane, click Create Basic Task….
- Name your task and click Next.
- Configure the task to run at your desired schedule (daily, weekly, etc).
- In the Start a Program section, input cleanmgr.exe in the Program/script box and /SAGERUN:1 in the Add arguments box.
Scheduling Disk Cleanup with Task Scheduler ensures regular maintenance of disk space without manual initiation.
5. Using PowerShell for enhanced control
- Press the Windows key, type PowerShell and select Run as administrator from the results.
- Run the PowerShell Script:
- Use the following script:
$volumeCaches = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches" foreach ($key in $volumeCaches) { New-ItemProperty -Path "$($key.PSPath)" -Name StateFlags0000 -Value 2 -Type DWORD -Force | Out-Null } Start-Process -Wait "$env:SystemRoot\System32\cleanmgr.exe" -ArgumentList "/sagerun:0"
- Save the script as cleanup.ps1 and execute it.
- Use the following script:
This PowerShell script gives you finer control over the cleanup process and can be easily integrated into larger automation frameworks.
6. Automate the Cleanup task using Group Policy
- Press the Windows key, type gpmc.msc, and open Group Policy Management Console.
- Create or Edit a Group Policy Object (GPO):
- Navigate to the target OU (Organizational Unit).
- Right-click and select Create a GPO in this domain, and Link it here….
- Name your GPO and click OK.
- Configure the GPO:
- Right-click on the new GPO and select Edit.
- Navigate to Computer Configuration > Policies > Windows Settings -> Scripts (Startup/Shutdown).
- Right-click on Startup, select Properties, then Add.
- Browse to your cleanup scripts such as cleanup.bat or cleanup.ps1 you’ve created in the previous solutions and add them.
Using Group Policy allows you to deploy the automated cleanup task across multiple machines in a domain environment, ensuring consistent disk space management.
By following these steps, you can automate the Disk Cleanup process in Windows, ensuring regular and efficient maintenance of your system’s storage without user intervention. Regularly check your automated tasks to ensure they run smoothly and adjust settings as needed to keep your system optimized.
While you’re at this, you might get extra info from our Windows 11 Disk Cleanup guide. Also, you can follow the highlighted guide if Disk Cleanup is missing.
For any suggestions or questions, hit the comments section below and let us know about them.