WinSXS folder is the component store of Windows vista and later operating systems. Windows OS stores all its core components to WinSXS directory. The WinSXS folder is the only location that the core system components found on the system and all the system files you see in their usual locations, in the windows directory structure, are hard linked back to the WinSXS folder. WinSXS folder is the only location that OS stores its components; everything else are just hard links. To prove the later point you can use the fsutil to check the hardlinks of a system file.
So, WinSXS starts large! But why is growing larger? The answer is updates. Every time a binary updates, a new version of the whole component is released and the old version is retained for reliability reasons in the component store. The updated version of a component is projected to the system (hardlinked) but the old version is retained with no hardlinks. This is the reason an update can be safely uninstalled from the system. If you uninstall an update from the system the next higher version of the component is used and other component changes may also be triggered as a result of dependencies.
Note, that WinSXS folder sometimes is perceived to be much larger than actually is. This misconception is because windows explorer and dir command are not aware of the difference between actual files and hardlinks. To have a better view of the disk space consumed by WinSXS you can use the SysInternal’s du utility (du -v c:windowswinSXS).
It is obvious that you cannot perform a WinSXS cleanup manually because it will cause problems to the OS. You can take advantage though of some features Windows 8 and Windows Server 2012 have introduced to cleanup some files.
Features on Demand
Windows 8 and windows Server 2012 introduced a new feature called “features on demand”. Features on demand are simply a feature that allows you to remove role and feature payloads from the OS to conserve diskspace. By default, windows OS stores under %windir%WinSXS folder all feature and role payloads, either installed or not, making an OS able to add features and roles without the need of an installation source.
In windows Server 2012 you can remove those payloads by using the powershell command uninstall-windowsfeature with the -remove switch. In case you want later to install a feature of which you previously removed its payload from the system; you can use the install-windowsfeature command. Install-windowsfeature will try to install a windows feature from the following source locations: local winSXS store or Windows Update in case of a payload removal from the local WinSXS store. You can also specify the -source switch to instruct the command to seek payloads from the alternate source path specified instead of windows update.
To cleanup all windows feature payloads from the system you currently don’t use, execute the following command:
The first part of the command gets the windows features that are not installed on the system and have its payloads available and pipes it in the uninstall-windowsfeature command for removal.
In case of windows 8 the powershell cmdlet above won’t work; thus it is required to use dism.exe instead, which can also be used in Windows 2012. To get features installation status:
To get a feature state status:
To remove a feature:
WinSXS cleanup from superseded components
In order to perform a WinSXS cleanup, you can remove any backup files created during the installation of a service pack by using the following command:
Note, that after you execute that command you will no longer be able to uninstall the service pack.
You can further perform a WinSXS cleanup by removing any superseded components:
Note, that the /ResetBase switch can only be used in Windows 2012R2+ and Windows 8.1+ in order to reset the base of superseded components and optimize the WinSXS cleanup process
What about a user interface (UI)?
Natively in windows 8 and after KB2852386 update in windows 7, disk cleanup utility supports cleaning the winSXS store. Just right mouse click your system drive, select properties and press disk cleanup. From that point forward select cleanup system files where you can select the Windows Update Cleanup option which cleans up the WinSXS cache.