Skip to main content

Script to Compress WinSXS

Compress WinSXS:

A Script to compress WinSXS folder resided in Windows directory.

if you are concern about the growing size of WinSXS folder taking so much of space then you can use this powershell script to reduce the size by compressing WinSXS folder data.
This script is very usefull in the case when you need to compress WinSXS folder in large number of Servers/Desktops environment.

#——————————————–
# Script to compress WinSXS folder
try {
$winDir = “$($env:windir)”
$winSxSDir = “$winDir\WinSxS”
$aclPath = “$winDir\WinSxS.acl”
$serviceMSI = “msiserver”
$serviceTI = “TrustedInstaller”

Stop-Service $serviceMSI
Stop-Service $serviceTI

Set-Service -Name $serviceMSI -StartupType Disabled
Set-Service -Name $serviceTI -StartupType Disabled

icacls.exe $winSxSDir /save $aclPath /t

takeown /f $winSxSDir /r

icacls $winSxSDir /grant “$($env:USERDOMAIN)\$($env:USERNAME)”:”(F)” /t

compact /s:$winSxSDir /c /a /i *

icacls $winSxSDir /setowner “NT SERVICE\TrustedInstaller” /t

icacls $winDir /restore $aclPath

Set-Service -Name $serviceMSI -StartupType Automatic
Set-Service -Name $serviceTI -StartupType Automatic
}
catch {
Write-Host -ForegroundColor Red $Error[0]
}
#——————————————–

Note: Please note if server/desktop services (Msiserver & TrustedInstaller) are already stopped and in disabled state then this script will modify both services to automatic state.


Please find the script below you can also download the script from here.

https://www.dropbox.com/s/ojvavujuxpwt20m/Compress%20Winsxs.Bat?dl=0



Thanks for Reading my Blog

Enjoy Maddi

Comments

karteek varma said…
sc query msiserver
sc query TrustedInstaller

sc stop msiserver
sc stop TrustedInstaller

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

icacls "%WINDIR%\WinSxS" /save "%WINDIR%\WinSxS.acl" /t

takeown /f "%WINDIR%\WinSxS" /r

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

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

icacls "%WINDIR%\WinSxS" /setowner "NT SERVICE\TrustedInstaller" /t

icacls "%WINDIR%" /restore "%WINDIR%\WinSxS.acl"
del "%WINDIR%\WinSxS.acl"

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

sc start msiserver
sc start TrustedInstaller

Popular posts from this blog

ESM Log size is full - How to clear

                                            ESM log Size is full ---- How to Clear If your getting the below error in event viewer you can follow the below steps and solve it. Generally when we open Dell open manage console, suddenly we see that Hardware log status is showing critical and event logs are filling saying ESM log is full... We need to clear the ESM logs regularly before it reaches 100%. However please follow the below command and procedure before clearing the logs. Open Dell Manage console, go to logs tab. Then select ESM logs, you will see an export option. Export the logs and save it on local drive for future use. Now open command prompt and Runas administrator. Type omconfig system esmlog action=clear Done, ...
  PowerShell DSC log amount issue on operating system drive Overview Problem Impact Microsoft Ticket (Workaround) solution References Overview When using PowerShell DSC on a configured system in some (seldom) cases it can lead to log amount issues in a specific folder. The following folder grows (over time) so several GB size holding hundreds and thousands of JSON log files as visible in the following screenshot: Also sometimes it looks like this: Problem The problem is (but must not be) related to DSC configuration issues as far as it could be analyzed. The log folder „Configuration Status“ is filled with sometimes up to 7 Megabyte sized JSON files. This log folder (based on our analysis) is used for sending reports to report server but is not cleaned up automatically. Impact Some PowerShell DSC managed systems need extensive disk space due to log directory grown to 40 Gigabyte plus. This causes an alert in disk space / availability monitoring and could in some cases lead to non w...

System Volume Information is taking more space

On one of the servers (running Windows Server 2012 R2) I faced a problem with the lack of free space on a system drive. I have cleared all resource-consuming locations ( WinSxS , TEMP directories, user profiles,  outdated updates , etc.), but it didn’t have any evident effect. At last, I have found that a large part of a system disk has been occupied by  System Volume Information  folder. Let’s consider why we need System Volume Information folder in Windows systems, what is stored in it and how to clean up it. Note . The instructions given in this article are applicable to other Windows versions as well:   Windows 10, Windows 7, Windows 8, Windows 2008 R2, Windows 2012 / 2012 R2. System Volume Information  folder is in the root of each disk. System data related to system recovery and Shadow Copy Service are stored in it. By default it is hidden and only the SYSTEM has access to it. Even the administrator cannot open it and look through the contents of th...