[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')] param( [switch]$IncludeJumpLists, [switch]$Apply ) $ErrorActionPreference = 'Stop' $recent = Join-Path $env:APPDATA 'Microsoft\Windows\Recent' if (-not (Test-Path -LiteralPath $recent -PathType Container)) { throw "Каталог не найден: $recent" } $files = @( Get-ChildItem -LiteralPath $recent -File -Force -ErrorAction SilentlyContinue | Where-Object { $_.Extension -eq '.lnk' } ) if ($IncludeJumpLists) { foreach ($name in @('AutomaticDestinations', 'CustomDestinations')) { $directory = Join-Path $recent $name if (Test-Path -LiteralPath $directory -PathType Container) { $files += @( Get-ChildItem -LiteralPath $directory -File -Force -ErrorAction SilentlyContinue ) } } } $bytes = ($files | Measure-Object -Property Length -Sum).Sum if ($null -eq $bytes) { $bytes = 0 } Write-Host ("Файлов истории: {0}, объём: {1:N1} MB" -f $files.Count, ($bytes / 1MB)) $files | Select-Object Name, Length, LastWriteTime | Format-Table -AutoSize if (-not $Apply) { Write-Host 'Предпросмотр. Для очистки добавьте -Apply.' return } $removed = 0 $failed = 0 foreach ($file in $files) { if ($PSCmdlet.ShouldProcess($file.FullName, 'Удалить элемент истории')) { try { Remove-Item -LiteralPath $file.FullName -Force -ErrorAction Stop $removed++ } catch { $failed++ Write-Warning "Не удалось удалить $($file.FullName): $($_.Exception.Message)" } } } Write-Host "Удалено: $removed, ошибок: $failed"