Bobcares

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

by | Apr 27, 2021

Wondering how to Clean Up and Compress WinSxS Folder on Windows Server/Windows 10? We can help you with it.

As part of our Server Management Services, we assist our customers with several Windows queries.

Today, let us see how our Support techs 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.

  • Initially, optimize the component store and remove old versions of Windows component files left after installing Windows updates.
  •  Features on Demand – allows us to remove unused Windows components from the disk.
  • 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

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? We can help you]

Conclusion

In short, we saw how our Support Engineers Clean Up and Compress WinSxS Folder on Windows Server/Windows 10

Are you using Docker based apps?

There are proven ways to get even more out of your Docker containers! Let us help you.

Spend your time in growing business and we will take care of Docker Infrastructure for you.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

3 Comments

  1. Chris

    Thanks for this piece – it’s the most concise run through of how to shrink that ridiculous WinSxS folder

    Reply
    • Hiba Razak

      Thank you,

      Reply
  2. TM

    One major caveat about this process is that you might be compressing in-use operating system files, which isn’t great from a performance point of view.

    If you note that “Shared with Windows” figure after running DISM with /AnalyzeComponentStore, that consists of files that are in use, mainly in %Windir%\System32. So maybe that 8GB figure doesn’t looks so bad if you consider that nearly 3/4ths of it is actual system files.

    To see which files “in” System32 are actually just symbolic links to files in WinSxs, you can run the following:

    Get-ChildItem -Path “C:\windows\system32” -Force | Where-Object { $_.LinkType -ne $null } | ft FullName,Linktype,Target

    Going back to the output from DISM… /AnalyzeComponentStore, running the /StartComponentCleanup switch should clean up Backups, Cache and Temporary Data.

    You can get more gains – as mentioned briefly at the beginning of the article – if you target Disabled Features, by can completely removing them if you don’t need them.

    In Powershell, run ‘Get-WindowsFeature | where installstate -eq “available”‘. This will list features available on disk, but which aren’t installed yet.

    If you are certain you won’t want these in future, you can run ‘Get-WindowsFeature | where installstate -eq “available” | Remove-WindowsFeature -Remove’. This will shrink WinSxs a fair amount in that “Backups and Disabled Features” area after you run /StartComponentCleanup /Resetbase. It also means that Windows updates are faster in future because it’s not updating packages you’re not using (not sure if download size for updates are reduced as well).

    The main caveat (other than creating a system restore point first just in case) is that if you decide you do want any of these features later on, you will need a Windows installation disk or ISO to reinstall them.

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.