diff --git a/Cleanup-SystemTempFiles.ps1 b/Cleanup-SystemTempFiles.ps1 index 9d8a12c..e97e87d 100644 --- a/Cleanup-SystemTempFiles.ps1 +++ b/Cleanup-SystemTempFiles.ps1 @@ -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) ) {