×


Clean Up and Compress WinSxS Folder on Windows Server / Windows 10 - Do it Now ?

The WinSXS folder contains every operating system file. When Windows installs updates, it drops the new Windows component in the WinSXS folder and keeps the old component in the WinSXS folder.

This means that every Windows Update you install increases the size of your WinSXS folder.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Windows queries.

In this context, we shall look into how to clean up the WinSxS folder on Windows Server 2016/2019.


Clean Up and Compress WinSxS Folder on Windows Server/Windows 10

The WinSxS directory will grow in size over time. 

Moreover, its size is not limited by anything.

Today, let us see the WinSxS folder in Windows, the reasons of its constant growth and safest ways to clean up the WinSxS folder on Windows Server 2016/2019.

1. Initially, optimize the component store and remove old versions of Windows component files left after installing Windows updates.

2. Features on Demand – allows us to remove unused Windows components from the disk.

3. Finally, enable NTFS compression on the WinSxS folder – a way to reduce the size of the WinSxS directory using the built-in compression of the NTFS file system.


Steps to Clean Up and Compress WinSxS Folder on Windows Server/Windows 10:

1. Firstly, get the current size of the WinSxS folder on Windows by opening the properties of the %windir%\WinSxS folder in File Explorer (or use a PowerShell script). 

Most file managers (including File Explorer) show a slightly larger WinSxS folder size than it takes on disk.

We can find out the real size of the WinSxS folder on disk using the du tool from Sysinternals:

du -v c:\windows\winSXS

We can also analyze the size of the component store (WinSxS folder) using the DISM command:

Dism.exe /Online /Cleanup-Image /AnalyzeComponentStore
Deployment Image Servicing and Management tool
[==========================100.0%==========================]
Component Store (WinSxS) information:
Windows Explorer Reported Size of Component Store : 8.44 GB
Actual Size of Component Store : 8.15 GB
Shared with Windows : 5. 74GB
Backups and Disabled Features : 1.97 GB
Cache and Temporary Data : 438.31 MB
Date of Last Cleanup : 2021-02-22 20:37:29
Number of Reclaimable Packages : 1
Component Store Cleanup Recommended : Yes
The operation completed successfully.

As we can see, we can reduce the size of the WinSxS folder by (1,97 + 0,44) GB.

The DISM command also allows us to check and repair our Windows image:

DISM /Online /Cleanup-Image /RestoreHealth


How to Clean Up the Component Store (WinSxS folder) on Windows ?

Initially, clear the Windows Component Store (the WinSxS folder) by optimizing the storage with the command:

Dism.exe /Online /Cleanup-Image /StartComponentCleanup

The StartComponentCleanup DISM option is supported on all Windows versions starting from Windows 8 and Windows Server 2012.

After cleaning is complete, check the current size of the component store:

Dism.exe /Online /Cleanup-Image /AnalyzeComponentStore

After that, we will not be able to remove installed updates or Service Packs and the Uninstall button will disappear from the Uninstall an Update Control Panel item).

To clean up old versions of components, run:

Dism.exe /Online /Cleanup-Image /StartComponentCleanup /ResetBase

In Windows 7 and Windows Server 2008 R2, an additional DISM option was used to clean up old versions of components that were left over after installing service packs:

DISM /online /Cleanup-Image /spsuperseded


We can also remove old update files using the "Disk Cleanup" wizard:

1. Firstly, run the cleanmgr command as an administrator

2. Then, select the disk and in the next window, click the “Clean up system files” button.

3. Finally, select the "Windows update cleanup" option. The Disk Cleanup tool will show how much space we can free up by deleting old Windows update files. In this example, this is 324 MB.

Click OK to start the cleanup.

After we finish cleaning up the component store using DISM, we can check how much disk space has been freed.


How to Enable NTFS Compress on WinSxS Folder on Windows 10 ?

Another way to reduce the size of the WinSxS directory on Windows 10 is to compress the directory contents on the level of the NTFS file system.

As in case of any non-standard intervention into the system configuration, it is strongly recommended to create a full backup of our Windows 10 image.

1. Firstly, open the command prompt as administrator.

2. Then, stop and disable Windows Installer and Windows Module Installer services:

sc stop msiserver
sc stop TrustedInstaller
sc config msiserver start= disabled
sc config TrustedInstaller start= disabled

3. Let us backup the Access Control Lists (ACLs) assigned to the files and folders in the WinSxS directory using the built-in icacls tool. A backup copy of an ACL is a plain text file that lists all files and directories and the NTFS permissions assigned to them (later this file will be needed to restore the original ACLs):

icacls “%WINDIR%\WinSxS” /save “%WINDIR%\WinSxS_NTFS.acl” /t

4. Assign us as an owner of the WinSxS folder and all its subfolders:

takeown /f “%WINDIR%\WinSxS” /r

5. Grant our account full control permissions on the WinSxS directory:

icacls “%WINDIR%\WinSxS” /grant “%USERDOMAIN%\%USERNAME%”:(F) /t

6. We can now compress files in the WinSxS directory using the compact command. Because some of the files can be used by Windows, we need to specify the /i option. Otherwise, compression will stop at the first locked file (in Windows 10, we can use more advanced LZX compression):

compact /s:”%WINDIR%\WinSxS” /c /a /i *

7. Restore the owner of the WinSxS directory back to TrustedInstaller:

icacls “%WINDIR%\WinSxS” /setowner “NT SERVICE\TrustedInstaller” /t

8. Restore the original ACLs for the WinSxS folder items using the ACL backup file we created earlier:

icacls “%WINDIR%” /restore “%WINDIR%\WinSxS_NTFS.acl”

9. Restore the default startup type for the Windows Installer and Windows Module Installer services:

sc config msiserver start= demand
sc config TrustedInstaller start= demand

Now check the current size of the WinSxS folder.


These commands can either be run separately (then it is much easier to track the results of each of them) or used in a single script file. 

If we run it, the described compression procedure for items in the WinSxS folder will start.


[Need assistance in fixing Windows Server errors? We can help you. ]


Conclusion

This article covers methods to Clean Up and Compress WinSxS Folder on Windows Server/Windows 10. 

WinSxS folder in Windows is the reasons of its constant growth and ways to clean up it. 

The C:\Windows\WinSxS directory is the repository of Windows components. This directory contains DLLs, binary and XML files necessary for installation and operation of various Windows roles or features.

When installing the Windows updates (usually this happens every month), the new version of the updated component is installed on the system, while the old one is saved to the WinSxS folder (it is necessary to provide compatibility and make it possible to rollback to the previous versions of the components when you uninstall the Windows update).


To clean up the WinSxS folder on Windows 10 and Windows Server 2016/2019:

1. Optimize the component store and remove old versions of Windows component files left after installing Windows updates;

2. Features on Demand – allows you to remove unused Windows components from the disk;

3. Enable NTFS compression on the WinSxS folder – a way to reduce the size of the WinSxS directory using the built-in compression of the NTFS file system.


How to Check the Actual Size of WinSxS Folder on Windows 10?

The easiest way to get the current size of the WinSxS folder on Windows is to open the properties of the %windir%\WinSxS folder in File Explorer (or use a PowerShell script). 

You can find out the real size of the WinSxS folder on disk using the du tool from Sysinternals:

du -v c:\windows\winSXS