I need to reclaim disk space on hundreds of machines that were recently upgraded to Windows 25H2. Cleanmgr can remove the previous installation interactively, but I haven't found a reliable way to automate that selection. I also tried combining DISM, takeown, icacls, and Remove-Item, but junction loops caused the scripts to fail. Is there a safe command-line or policy-based method that I can run remotely instead of logging into each computer?
4 Answers
cleanmgr /autoclean is sometimes suggested for this, but it isn't reliable in every deployment scenario. The configured /sageset and /sagerun approach gives you more control, especially when running the cleanup through a remote deployment tool.
Storage Sense can handle this through policy and is safer than manually deleting Windows.old. Depending on the upgrade state, Windows may also remove the previous installation automatically after the rollback window expires—usually around 10 days, though the timing can vary.
Avoid using takeown or icacls recursively on Windows.old. The junctions can redirect the operation into protected system locations, potentially changing ownership and permissions on unrelated files. Test any cleanup command on a disposable machine before deploying it broadly.
You can configure Cleanmgr once with cleanmgr /sageset:777, select the option for previous Windows installations, and note the registry value it creates. Then deploy that value to other machines and run cleanmgr /sagerun:777. For example: reg add "HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesPrevious Installations" /v StateFlags777 /t REG_DWORD /d 2 /f, followed by cleanmgr /sagerun:777. This avoids trying to take ownership of the directory directly.

Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures