Batch Script to Remotely Delete Windows.old Folder

Assuming that you performed an upgrade to Windows 10, a custom installation of Windows 10 without formatting the drive, or install Windows 10 on the same partition of a previous Windows installation. In this situation, you may have a “C:\Windows.old” folder left over after your new installation.

This folder contains a copy of the previous Windows installation, and it can be quite large, even taking up 20+ GB of space.  Windows does automatically delete the folder 30 days after the upgrade takes place, but because the folder is so large it can be beneficial to delete it before then.

Microsoft’s supported method is to use Windows Disk Cleanup tool to delete “previous windows installations”, but they do not provide a straightforward way to do this remotely or on a large scale for that you could use a batch script that contains three short commands.

The instructions below require administrator access. If you are not the administrator, please contact the administrator for assistance before continuing.

Copy these commands into a file then save that file with a .BAT extension to create a working batch script. Open Notepad and copy/paste the commands only given below:

The first command takes ownership of the Windows.old folder and contents.

TAKEOWN /F %SystemDrive%\Windows.old /A /R /D Y

Next command grants administrators access.
ICACLS %SystemDrive%\Windows.old /T /grant :r Administrators:F

The last command removes the entire Windows.old directory.
RD /S /Q %SystemDrive%\Windows.old

Click on the File menu > Save As and choose a location to save the file (place it on the Desktop for easier access). Click on the Save as type drop-down menu and select All Files.

That’s it; your batch file is ready for use.

Right click on the batch file and Run As Administrator. In doing so, you will automatically delete the Windows.old folder.

Group Policy can also be used to force run the script on startup, shutdown, logon, or logoff.