I have installed Hyper-V Server 2012 R2 on a server that had Hyper-V Server 2012. When I did this, the standard Windows.old
folder was created. I now would like to remove that folder safely. The standard way to do that with a full GUI would be to use Disk Cleanup, but of course I don't have that option on Hyper-V Server.
Is there a formal way to remove that folder in this scenario? I know if this was Server Core I could install the full GUI including Desktop Experience, but that would be a lot of nonsense just to cleanly remove a folder.
My primary reason for asking, as opposed to just doing rmdir /s
or some such, is that the Windows.old
folder has a lot of junctions, and I don't want to break anything in the production OS copy as part of doing this.
I first tried to copy and run cleanmgr.exe (Disk Cleanup tool), but it has too many dependencies on DLLs which are not present in Core/Hyper-V Server.
So instead I deleted the directory manually.
First I removed all junction points and symbolic links. To do this I used junction.exe from SysInternals. Copy the exe into a directory in your path. I ran it to get a list of all junctions:
I opened a PowerShell:
and ran the following script to find the relevant lines and execute junction.exe again:
This removed all junction points and the single symbolic link on my system.
back in cmd.exe I now executed three commands to clear permissions and delete all files:
In my test, I installed a new Hyper-V server 2012, then upgraded to 2012 R2, Windows.old is now gone and the system is running fine with all old junction targets intact.
I used Peter H's answer and confirmed it does work, however I needed to do this on multiple servers, so I modified his code into a powershell script that can be executed either locally or via PS remoting from another machine. This is the .ps1 file: