That one is already compressed by compact /compactos:always (in my case from 50.4MB to 22.5). I'll add it anyway though, thanks.
In case you are interested this is what I'm doing at the moment.. It is pretty stable.
The compression is a bit trial and error (lzx for things like installer that are never used like installer, xpress8k for things that are like assembly). Obviously deleting is better than compressing when you can (WindowsApps and SoftwareDistribution\Downloads in particular). Fonts is reasonable extra saving (377MB to 249MB compressed) but you need to take/restore ownership.
Code:
$compactDirectory = @(
("$env:programFiles", "", "xpress16k")
("${env:programFiles(x86)}", "", "xpress16k"),
("$env:homeDrive\MSOCache", "", "lzx"),
("$env:homeDrive$env:homePath\Documents", "", "xpress16k"),
("$env:homeDrive$env:homePath\OneDrive", "", "xpress16k"),
("$env:homeDrive$env:homePath\Downloads", "", "xpress16k"),
("$env:windir\Assembly", "","xpress8k"),
("$env:windir\Fonts", "NT SERVICE\TrustedInstaller", "xpress16k"),
("$env:windir\InfusedApps", "", "xpress16k"),
("$env:windir\Installer", "", "lzx"),
("$env:windir\Panther", "", "xpress16k"),
("$env:windir\SoftwareDistribution", "", "xpress16k"),
("$env:windir\System32\Catroot2", "", "xpress16k"),
("$env:windir\System32\LogFiles", "", "xpress16k")
)
#------------------------------------------------------------------------------------------------------------------------------------------------------
function takeOwn-folder ($folder) {
$toplevel = Split-Path $folder -leaf
if (Test-Path "$PSScriptRoot\$toplevel.acl") {Remove-Item "$PSScriptRoot\$toplevel.acl" -Force -ErrorAction 0}
icacls "$folder" /save "$PSScriptRoot\$toplevel.acl" /t
takeown /f "$folder" /r
icacls "$folder" --% /grant "%USERDOMAIN%\%USERNAME%":(F) /t
}
#------------------------------------------------------------------------------------------------------------------------------------------------------
function restoreOwn-folder ($folder, $owner) {
$toplevel = Split-Path $folder -leaf
$parentPath = Split-Path -parent $folder
icacls "$folder" /setowner "$owner" /t
icacls "$parentPath" /restore "$PSScriptRoot\$toplevel.acl"
Remove-Item "$PSScriptRoot\$toplevel.acl" -Force -ErrorAction 0
}
#------------------------------------------------------------------------------------------------------------------------------------------------------
For($i=0;$i -lt $compactDirectory.Count; $i++) {
$folder = $compactDirectory[$i][0]
$owner = $compactDirectory[$i][1]
$compression = $compactDirectory[$i][2]
if(Test-Path $folder) {
# take ownership if required
if ($owner -ne "") {takeOwn-folder -folder $folder}
Write-Host "Running " -NoNewLine
Write-Host "compact /c /s /a /f /q /i /exe:"$compression $folder"\*" -f White
compact /c /s /a /f /q /i /exe:$compression $folder\*
#restore ownership
if ($owner -ne "") {restoreOwn-folder -folder $folder -owner $owner}
}
}
What I've had problems with are these 3
Code:
# ("$env:windir\System32\DriverStore\FileRepository","","lzx"),
# ("$env:programData","NT AUTHORITY\SYSTEM","xpress16k"),
# ("$env:APPDATA","NT AUTHORITY\SYSTEM","xpress16k"),
Not sure if I've got the ownership wrong or what but windows doesn't work properly if I compress these.
I'd like to compress DriverStore as it is big but my screen goes all funny if I do...