[CmdletBinding()] param( [ValidateRange(1, 365)] [int]$OlderThanDays = 14, [switch]$Apply ) $ErrorActionPreference = 'Stop' $cacheDir = Join-Path $env:LOCALAPPDATA 'Microsoft\Windows\Explorer' if (-not (Test-Path -LiteralPath $cacheDir -PathType Container)) { Write-Host "Папка кэша не найдена: $cacheDir" return } $cutoff = (Get-Date).AddDays(-$OlderThanDays) $files = @(Get-ChildItem -LiteralPath $cacheDir -Filter 'thumbcache_*.db' -File -Force -ErrorAction SilentlyContinue | Where-Object { $_.LastWriteTime -lt $cutoff }) $total = 0 if ($files.Count -gt 0) { $total = ($files | Measure-Object -Property Length -Sum).Sum } Write-Host ("Файлов кэша старше {0} дней: {1}, объём: {2} МБ" -f $OlderThanDays, $files.Count, [math]::Round($total / 1MB, 2)) $files | Sort-Object Length -Descending | Select-Object @{Name = 'SizeMB'; Expression = { [math]::Round($_.Length / 1MB, 2) }}, LastWriteTime, Name | Format-Table -AutoSize if ($files.Count -eq 0) { Write-Host 'Нечего очищать.' return } if (-not $Apply) { Write-Host 'Это предпросмотр. Для удаления добавьте -Apply.' return } $removed = 0 $skipped = 0 foreach ($file in $files) { try { Remove-Item -LiteralPath $file.FullName -Force -ErrorAction Stop $removed++ } catch { $skipped++ Write-Verbose "Пропуск $($file.FullName): $_" } } Write-Host "Удалено файлов: $removed, пропущено занятых: $skipped" Write-Host 'При необходимости перезапустите проводник, чтобы он освободил старые файлы.'