How can I automate Windows.old cleanup after a Windows 25H2 upgrade?
Asked by
MellowPine42
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?
Answers
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.
Reply to this answer
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.
Reply to this answer
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.
Reply to this answer
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.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions