How can I automate removal of Windows.old after a Windows 25H2 upgrade?
Asked by
MapleOrbit42
I need to reclaim disk space on hundreds of systems 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 cleanup. I also tried combining DISM, takeown, icacls, and Remove-Item, but junction loops caused errors and prevented the directory from being removed. What is the safest way to perform this remotely without logging into each machine?
Answers
Storage Sense policies are another option if you already manage them centrally. Configure the policy to remove previous Windows installations and let the devices process it on their normal maintenance schedule. The `/autoclean` switch is sometimes suggested, but it may not work consistently for this scenario.
Reply to this answer
Cleanmgr can be scripted through its registry-backed presets. On a test machine, run `cleanmgr /sageset:777`, select Previous Windows installation(s), and save the settings. Then deploy the corresponding StateFlags777 registry value under `HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerVolumeCachesPrevious Installations` and run `cleanmgr /sagerun:777` with administrative privileges.
Reply to this answer
Windows normally removes the previous installation automatically once the rollback period ends, which is commonly around 10 days, though the exact timing can vary. If you need the space sooner, use a Storage Sense policy or the scripted cleanmgr preset rather than manually deleting the folder.
AmberPiano64: Iโve seen it take closer to 10 days in practice, so I wouldnโt rely on the automatic cleanup if disk space is urgent.
Reply to this answer
Avoid taking ownership and manually deleting Windows.old. Junctions and protected system folders can cause the process to follow paths it shouldnโt, and changing permissions may damage ownership or ACLs on other parts of the system. Test any cleanup method on a small pilot group first.
Reply to this answer
Add your answer
Answers are reviewed before publication.
CedarBlink5: Thatโs probably the route Iโll use if the installation cleanup doesnโt happen automatically after the rollback window expires.