param( [Parameter(Mandatory)] [String]$cacheDir, [Int32]$cacheAge=30 ); $cutoff = (Get-Date).AddDays(-$cacheAge); $allFiles = 0; $oldFiles = 0; $freedBytes = 0; Get-ChildItem -Path $cacheDir -Recurse -File | where { $_.extension -in '.jpg','.jpeg','.png','.ppm' } | ForEach { $allFiles++; if ($_.LastWriteTime -lt $cutoff) { $oldFiles++; $freedBytes += $_.Length; Remove-Item $_.FullName; } }; Write-Output $allFiles; Write-Output $oldFiles; if ($freedBytes -gt 1GB) { Write-Output "$([math]::round($freedBytes / 1GB, 2)) GiB"; } elseif ($freedBytes -gt 1MB) { Write-Output "$([math]::round($freedBytes / 1MB, 2)) MiB"; } elseif ($freedBytes -gt 1KB) { Write-Output "$([math]::round($freedBytes / 1KB, 2)) KiB"; } else { Write-Output "$($freedBytes) bytes"; }