cleanup chocolatey cache

This commit is contained in:
2024-07-03 16:37:56 -04:00
parent bcf8b87dc5
commit dbb6fefa07
+11
View File
@@ -129,6 +129,17 @@ If ( $ShadowCopies.Length -gt 1 ) {
}
}
# Delete old temp directories from Chocolatey cache
$ChocolateyCache = "${Env:WinDir}\Temp\chocolatey"
$ChocolateyTempDirs = Get-ChildItem -Path $ChocolateyCache -Directory -ErrorAction SilentlyContinue | Where-Object { $_.LastWriteTime -lt ((Get-Date) - $TimeDelta) }
If ( $ChocolateyTempDirs ) {
Write-Output "Deleting all temp directories not modified in ${OlderThan} day(s) from ""${ChocolateyCache}"""
ForEach ( $d in $ChocolateyTempDirs ) {
Try { Remove-Item $d -Force -Recurse -ErrorAction SilentlyContinue }
Catch { Write-Error $_.Exception.Message }
}
}
# Remove files from user profile directories
ForEach ( $userProfile in $(Get-UserProfiles) ) {