Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Windows 10 / How to Clean Up and Compress the WinSxS Folder on Windows 10/Windows Server?

June 7, 2022 Windows 10Windows Server 2016

How to Clean Up and Compress the WinSxS Folder on Windows 10/Windows Server?

In this article we will talk about the WinSxS folder in Windows, 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).

The WinSxS directory has grown in size over time. Moreover, its size is not limited by anything (although in practice the size of the WinSxS folder in Windows 10 rarely exceeds 15-20 GB).

list of files in winsxs on windows 10

Contents:
  • How to Check the Actual Size of WinSxS Folder on Windows 10?
  • How to Clean Up the Component Store (WinSxS folder) on Windows?
  • Remove Unused Roles and Features from Windows 10/Windows Server
  • How to Enable NTFS Compress on WinSxS Folder on Windows 10?

In this article, we’ll go over the safest ways to clean up the WinSxS folder on Windows 10 and Windows Server 2016/2019:

  • Optimize the component store and remove old versions of Windows component files left after installing Windows updates;
  • Features on Demand – allows you to remove unused Windows components from the disk;
  • 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.
Many users often ask: if it’s possible to manually delete files from the WinSxS folder? The answer is categorically NO! These actions can damage your Windows image. Though some attempts to remove files from the WinSxS folder can be successful, this method cannot be recommended.

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). But keep in mind that most file managers (including File Explorer) show a slightly larger WinSxS folder size than it takes on disk.

The fact is that the WinSxS directory contains a large number of hard links (symbolic links) to system files in other folders. File managers, when calculating the size of the WinSxS folder, take into account the size of files referenced by hard links, but this is not correct.

You can find out the real size of the WinSxS folder on disk using the du tool from Sysinternals:
du -v c:\windows\winSXS
how to check the real size of winsxs folder using du tool

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

Dism.exe /Online /Cleanup-Image /AnalyzeComponentStore

dism analyze component store - reporting winsxs folder real size

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 you can see, in this case, I can reduce the size of the WinSxS folder by (1,97 + 0,44) Gb.

The DISM command also allows you to check and repair your Windows image:

DISM /Online /Cleanup-Image /RestoreHealth

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

The fastest and easiest way to clear the Windows Component Store (the WinSxS folder) is to optimize the storage with the command:

Dism.exe /Online /Cleanup-Image /StartComponentCleanup

clenup winsxs component store with Dism 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

In my example, this reduced the size of the WinSxS folder by 2.4 GB.

The /StartComponentCleanup option has an additional /ResetBase option that allows you to remove all previous versions of components left after installing Windows updates. After that you won’t 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

You can also remove old update files using the “Disk Cleanup” wizard:

  1. Run the cleanmgr command as an administrator;
  2. Select the disk and in the next window, click the “Clean up system files” button;Clean up system files
  3. Then select the “Windows update cleanup” option. The Disk Cleanup tool will show how much space you can free up by deleting old Windows update files. In my example, this is 324 MB. Click OK to start the cleanup.Windows update cleanup using cleanmgr tool

After you finish cleaning up the component store using DISM, check how much disk space has been freed.
In addition, Windows 10/Windows Server 2016 Task Scheduler has a special automatic maintenance task that regularly optimizes and cleans up the WinSxS folder (same operation as DISM with StartComponentCleanup parameter). This StartComponentCleanup task is located under the \Microsoft\Windows\Servicing section of the taskschd.msc. This task runs in the background and automatically removes component versions older than 30 days that have been superseded by newer files.

You can start this task manually like this:

schtasks.exe /Run /TN "\Microsoft\Windows\Servicing\StartComponentCleanup"

StartComponentCleanup task

Remove Unused Roles and Features from Windows 10/Windows Server

Features on Demand on Windows allows to remove binary files of the unused roles from the WinSxS folder. You can remove roles and features binaries on Windows Server using the Uninstall-WindowsFeature PoweShell cmdlet.

Windows 10 does not have the Uninstall-WindowsFeature cmdlet, and you must use DISM.exe to remove features from the Windows image.

Note that DISM, unlike the Uninstall-WindowsFeature PowerShell cmdlet, doesn’t remove dependent features.

A complete list of available features in Windows 10 image can be obtained using the command:
DISM.exe /Online /English /Get-Features /Format:Table
DISM Get-Features list

To remove, for example, the TelnetClient feature from the Windows image (from the WinSxS folder), run the command:
DISM.exe /Online /Disable-Feature /Featurename:TelnetClient /Remove
DISM Disable Feature Remove

If you display the list of all on-demand features available in Windows, you will see that the component status has changed to Disabled with Payload Removed.

Thus, Windows allows to significantly reduce the size of the WinSxS folder by removing the unused components from the disk. The only thing is that this cleanup method suits only for the advanced users, who are familiar with the Windows 10 features and their purpose.

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.

Note. As in case of any non-standard intervention into the system configuration, you are strongly recommended to create a full backup of your Windows 10 image.
  1. Open the command prompt as administrator;
  2. 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’s 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
    backup ntfs permissions of winsxs folder files using icacls
  4. Assign yourself as an owner of the WinSxS folder and all its subfolders:
    takeown /f "%WINDIR%\WinSxS" /r
  5. Grant your account full control permissions on the WinSxS directory:
    icacls "%WINDIR%\WinSxS" /grant "%USERDOMAIN%\%USERNAME%":(F) /t
  6. You can now compress files in the WinSxS directory using the compact command. Because some of the files can be used by Windows, you need to specify the /i option. Otherwise, compression will stop at the first locked file (in Windows 10, you can use more advanced LZX compression):
    compact /s:"%WINDIR%\WinSxS" /c /a /i *
    compressing files in the winsxs folder using the compact.exe tool
  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 you 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:

how to saves pace on winsxs folder on windows 10?

As you can see, in our example the size of the WinSxS folder after the compression has reduced from 9.4GB to 6.5GB (about a third). Not bad, especially for a small-sized SSD-drive.

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 you run it, the described compression procedure for items in the WinSxS folder will start. You can download the ready-to-use batch file to enable NTFS compression on WinSxS here: winsxs_ntfs_compress.bat

You can use this script regularly because new uncompressed files will appear in the WinSxS folder after you install new Windows updates or apps.

What can be affected by compressing the WinSxS folder? Windows works transparently with compressed files. However, when processing such files, it may take additional CPU time to decompress/compress them. This may cause a slight slowdown when installing Windows components or updates. However, on modern CPUs, the file compression/ decompression operations are performed almost instantly, so the user may not even notice the real impact on performance.

22 comments
3
Facebook Twitter Google + Pinterest
previous post
Moving Exchange Mailboxes to Different Database
next post
Windows Defender Threat Service Has Stopped, Restart It Now

Related Reading

How to Connect VPN Before Windows Logon

November 14, 2023

Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

November 7, 2023

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

How to Use Ansible to Manage Windows Machines

September 25, 2023

22 comments

Maxim September 15, 2014 - 10:25 pm

Thank you very much!

Reply
fox October 22, 2014 - 8:23 pm

I tried your solution, but step 8 “Recover original ACLs to the WinSxS directory” failed with the following messages:
C:\Windows\WinSxS\Manifests\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.42_none_db5f52fb98cb24ad.cat: Access denied.
Successfully Processed 20618 files; Failed to process 1 file.

In fact it failed to process 24000 files because it aborted due to the Access Denied failure.
I tried to re-run the instruction and edited that line so it could pass that phase and it only processed 4 files more and failed again.

Are you able to hint how to proceed from now?

Reply
Max October 23, 2014 - 4:07 am

Check current permission on file x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.42_none_db5f52fb98cb24ad.cat. Try take ownership of file and grant your account full rights to it. Next repeat step 8 again.
Or manually set the permissions on the file in accordance with the data in the file WinSxS_NTFS.acl

Reply
Rob Donovan November 8, 2014 - 2:19 pm

Hi,

It also failed on me with the restoring ‘TrustedInstaller’ part, saying access denied.

I presume this is because the first steps gave my user Ownership, but, we didnt add my user as a user to the actual permissions.

So, when you try to change back to TrustedInstaller, your user doesnt have the access to do that. Atleast that is how I see it.

So, I had to run this instead, to get back to TrustedInstaller Owner:

icacls “%WINDIR%\WinSxS” /grant Rob:(F) /t /c
icacls “%WINDIR%\WinSxS” /setowner “NT SERVICE\TrustedInstaller” /t /c
icacls “%WINDIR%\WinSxS” /remove Rob /t /c

It gives my user ‘Rob’ fullcontrol first, then changes to TrustedInstaller, and then finally removes my user permission for ‘Rob’.

Replace ‘Rob’ with whatever your username is.

It seems that even though you can take ownership and then do things, you dont have permission to change ownership back, unless you give your user ‘Full control’ permissions.

HTHs,

Rob.

Reply
Max November 12, 2014 - 7:26 am

Hi, Rob!
Thanks for your comment, but we give current user Full Control permission on step 5, then execute command:
icacls “%WINDIR%\WinSxS” /grant “%USERDOMAIN%\%USERNAME%”:(F) /t
You must just replace %USERDOMAIN%\%USERNAME% on your username

Reply
patrick November 15, 2014 - 12:52 pm

I’m sorry but compressing winSXS seems to increase size on disk? in my case it does 🙁
winSXSfolder shows decrease size on disk, but when I check the drive full size it actually increased.

Reply
patrick November 15, 2014 - 1:04 pm

my mistake, forgot to restart PC now it shows correct size 🙂

Reply
genetix December 3, 2014 - 9:07 am

Extremely good looking guide. Most be one and only on web to go through this deep analyze of how to go further in data usage.
Honestly, since Microsoft is being a brick while operating systems with full support should take less than 500MB in size while online and then consider what people actually wants to use in os the whole idea of increasing size to raise hardware market supported by all new hardware manufacturers is good for marketing, but there should be some system ripped to WinPE level where only thing that should take space is few KB driver base for all devices, but since now days a simply 500KB audio driver can turn to 250MB totally idiotic bloatware it’s hilarious really. Sadly this is possible at linux side, but Microsoft sure is enjoying the install size being around 20-30GB in full with only barebone components in the machines.

Reply
Ricardo Fort December 3, 2015 - 1:24 am

To solve the “sc config msiserver start= demand” Access is denied, use NSudo and run the same command again:
sc config msiserver start= demand

Reply
Dan Dar3 August 7, 2016 - 2:55 pm

Nice one Woshub.com, simply lifting the WinSXS compressing part from my blog and not giving any credit! http://dandar3.blogspot.com/2013/01/how-to-ntfs-compress-windows-winsxs.html

Reply
Junior November 17, 2016 - 4:05 pm

Does this work with windows server 2008 sp2?

Reply
admin November 30, 2016 - 7:00 am
  • “Features on Demand” appeared only in Windows Server 2012 / Win 8
  • To use DiskCleanup tool you nee to install update KB2852386 (http://support.microsoft.com/kb/2852386))
  • You can compress WinSxS folder this way in any supported version of Windows
Reply
Kent April 15, 2019 - 2:21 am

KB2852386 is for Server 2008 R2. Is not applicable to Server 2008 SP2. For Server 2008 SP2, use Compcln.exe.

Reply
TheNetAvenger October 23, 2018 - 2:44 pm

This is a great guide.

You might want to update and mention that current versions of Windows 10 automatically clean up the WinSXS folder – and note which things you mention are not a part of the automatic cleanup.

As Microsoft states from their cleanup Doc…
“Windows 10 and Windows Server 2016 automatically reduce the size of the WinSxS folder by using methods similar to the ones described in this topic, in addition to internal processes, such as uninstalling and deleting packages with components that have been replaced by other components with newer versions. Previous versions of some components are kept on the system for a period of time, allowing you to rollback if necessary.”

This might help users, so they aren’t taking time to repeat steps that Windows 10 is now doing for them. It might also help with confusion when the size doesn’t change, and to know when they can still rollback items.

Reply
admin October 30, 2018 - 5:57 am

Do you talk about a task named StartComponentCleanup (located in the task scheduler section \Microsoft\Windows\Servicing)? This task deletes replacement packages files older than 30 days.

Reply
Martin January 3, 2019 - 1:17 pm

When you issue `compact /s:”%WINDIR%\WinSxS” /c /a /i` instead of `compact /s:”%WINDIR%\WinSxS” /c /a /i *`, the WinSxS directory *itself* will be marked as “compressed”, too. This means any newly created subfolders and files will be compressed right from the start and it’s no longer necessary to run this script periodically.

Reply
Gigamegs July 26, 2019 - 4:30 pm

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

Didn’t work for me instead use: icacls “%WINDIR%\WinSxS” /grant User:F /t

[1]https://stackoverflow.com/questions/2928738/how-to-grant-permission-to-users-for-a-directory-using-command-line-in-windows

Reply
Anders Lindström October 9, 2019 - 7:04 am

Very good article. Helped me 100%.
Before 100Mb, after 8Gb.

Reply
Paul November 5, 2019 - 10:47 pm

This should be included script in the Citrix Optimization tool and BASE Image Script Framework for non-persistent virtual desktops. Reduced free space from 3.42GB to 6.47GB saving limited server SSD intellicache for our six servers. Great work, Thank you.

Reply
Serg April 22, 2021 - 4:53 pm

On the web you can find in another script that allows to reduce the size of the WinSxS folder — WinSxSLite (by Christian Bering Boegh). According to the developer, this script searches the latest version on dll files in WinSxS, makes symbolic links to them from all previous versions and removes the old file versions. It is no recommended to use WinSxSLite, because in spite of the idea being good, the result of running the script is unpredictable, and though the WinSxS folder size is reduced, some Windows components can be damaged

Reply
Josean Rodriguez May 24, 2021 - 10:21 am

Hi!
I made a deeply cleanup from Windows 10, and now, I cant install Windows Media Player, is not the files to enable via powershell this feature.

It’s possible to reinstall Features and apps deleted in Winsxs and made possible reinstall it?

Thanks

Reply
Ricardo October 9, 2022 - 1:53 am

Great!!! Really helpful!

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • How to Connect VPN Before Windows Logon

    November 14, 2023
  • Removing Azure Arc Setup Feature on Windows Server 2022

    November 9, 2023
  • Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

    November 7, 2023
  • Send Emails with Microsoft Graph API and PowerShell

    November 6, 2023
  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • How to Repair EFI/GPT Bootloader on Windows 10 or 11
  • How to Restore Deleted EFI System Partition in Windows
  • Network Computers are not Showing Up in Windows 10/11
  • Updating List of Trusted Root Certificates in Windows
  • How to Create a Wi-Fi Hotspot on your Windows PC
  • How to Sign an Unsigned Device Driver in Windows
  • How to Download APPX File from Microsoft Store for Offline Installation?
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top