From dbb6fefa072adc1a02fc030a4bc2fadca51df878 Mon Sep 17 00:00:00 2001 From: David Yoder Date: Wed, 3 Jul 2024 16:37:56 -0400 Subject: [PATCH] cleanup chocolatey cache --- Cleanup-SystemTempFiles.ps1 | 11 +++++++++++ 1 file changed, 11 insertions(+) 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) ) {