[CmdletBinding()] param( [string[]]$Path, [int]$Days = 0, [string]$OutputPath, [switch]$Json ) $ErrorActionPreference = 'Stop' if ($Days -lt 0) { throw 'Параметр Days не может быть отрицательным.' } $defaults = @( "$env:SystemRoot\Minidump", "$env:SystemRoot\MEMORY.DMP", "$env:LOCALAPPDATA\CrashDumps" ) if (-not $Path) { $Path = $defaults } $files = foreach ($item in $Path) { if (Test-Path -LiteralPath $item -PathType Container) { Get-ChildItem -LiteralPath $item -File -Filter '*.dmp' -ErrorAction SilentlyContinue } elseif (Test-Path -LiteralPath $item -PathType Leaf) { Get-Item -LiteralPath $item -ErrorAction SilentlyContinue } } if ($Days -gt 0) { $cutoff = (Get-Date).AddDays(-$Days) $files = $files | Where-Object { $_.LastWriteTime -ge $cutoff } } $rows = $files | Sort-Object LastWriteTime -Descending | Select-Object FullName, @{ Name = 'SizeMB'; Expression = { [math]::Round($_.Length / 1MB, 1) } }, LastWriteTime, @{ Name = 'AgeDays'; Expression = { [int]((Get-Date) - $_.LastWriteTime).TotalDays } } Write-Host "Найдено дампов: $($rows.Count)" if ($Json) { $text = $rows | ConvertTo-Json -Depth 4 } else { $text = $rows | Format-Table -AutoSize | Out-String -Width 240 } if ($OutputPath) { $text | Set-Content -LiteralPath $OutputPath -Encoding UTF8 Write-Host "Отчёт сохранён: $OutputPath" } else { $text }