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.