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.
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
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