Disk Cleanup via powershell

Run PowerShell as Administrator

Define the path to the Disk Cleanup Manager

$cleanmgrPath = “$env:SystemRoot\System32\cleanmgr.exe”

Run Disk Cleanup with the system cleanup option

Start-Process $cleanmgrPath -ArgumentList “/sageset:65535 /sagerun:65535” -Wait

Clean up system files including Windows.old

Start-Process $cleanmgrPath -ArgumentList “/sagerun:65535 /cleanup:30” -Wait

Pararmater to pick Windows update cleanup and other options

1 Like

How can you choose in advance which options you want to pick so they can be parameterized?

guess that is the million-dollar question, so guess right now no way to run disk cleanup silently?

Sure, there is–but only with whatever predefined parameters you have set with /sageset . What we need is how to encode the sageset parameters in the registry so that they can be set/selected from the deployment for this.