One of my Windows Server 2012 R2 ran out of space. A quick folder analysis using the free portable tool TreeSize revealed that both Windows.old and WinSxS folders are the ones taking most of the spaces.
On Windows desktop systems, both folders are easy to clean up with the built in tool Disk Cleanup Utility. But, it’s not the case in Windows Server, especially the more recent versions like 2012 R2. You probably could enable Desktop Experience feature to bring back the Disk Cleanup Utility but it won’t guarantee to clean up these two giant folders managed by the system upgrades and updates. If you are facing the same challenge as I do, here are the options you can take away.
Clean up WinSxS folders on Windows Server 2012 R2
WinSxS, aka Windows component store, contains all the files required for a Windows installation as well as any updates to those files within the component store. Therefore, the folder could become quite big over time. Because it’s associated with system installation it’s not a good idea just simply deleting the folder. Rather, utilizing a command-line tool called DISM, Deployment Image Servicing Management, is way more appropriate. It has a parameter /cleanup-image
that provides a few more advanced options to reduce the size of the WinSxS folder.
First of all, you can run the following to analyze the component store to see what’s included in there.
dism /online /cleanup-image /AnalyzeComponentStore
Then, run the following to remove superseded and unused system files from the system and reset the base so all existing updates cannot be removed after the command is completed.
dism /online /cleanup-image /StartComponentCleanup /ResetBase
It didn’t clean up a whole lot in my case, only claimed back a little over 1 GB space.
Note: If you are somehow still using Windows Server 2008 R2, installing KB2852386 after enabling Desktop Experience feature makes things a lot easy to clean up right with the Disk Cleanup Utility tool.
How to clean up WinSxS folder on Windows 2008 R2
How to clean up Windows.old on Windows Server 2012 R2
With Disk Cleanup out of the equation, manual cleanup seems to be the option left. Thanks to this Q&A at ServerFault, here is what I did to bring back over 50 GB of storage space.
First of all, run Sysinternals junction.exe utility to get a list of all junctions in a text file, junc.txt on my desktop.
junction.exe -s -q c:\windows.old > %UserProfile%\desktop\junc.txt
Then, run the following script in PowerShell to remove all junction points and single symbolic links on the system.
foreach ($line in [System.IO.File]::ReadLines("$env:userprofile\desktop\junc.txt")) { if ($line -match "^\\\\") { $file = $line -replace "(: JUNCTION)|(: SYMBOLIC LINK)","" & $env:userprofile\desktop\pstools\junction.exe -d "$file" } }
Replace with the correct path for junction.exe utility and the junc.txt files, if needed.
Once that’s done, run the following to take over ownership of the windows.old folder.
takeown /f c:\windows.old /r /d y
And reassign the full control rights to everyone.
cacls c:\windows.old /t /g everyone:F
Then, finally to remove the whole folder.
rmdir /s /q c:\windows.old
It may take a little while for the command to complete but once it’s done you will be so delighted to see how much space you just brought it back to life. Enjoy.