[CmdletBinding()] param( [int]$MaxAgeDays = 30, [string]$OutputPath, [switch]$Json ) $ErrorActionPreference = 'Stop' if ($MaxAgeDays -lt 1) { throw 'Параметр MaxAgeDays должен быть больше нуля.' } $points = @() try { $points = @(Get-ComputerRestorePoint -ErrorAction Stop) } catch { Write-Warning "Точки восстановления недоступны: $($_.Exception.Message)" } $pointRows = foreach ($point in $points) { $created = $null try { $created = [System.Management.ManagementDateTimeConverter]::ToDateTime($point.CreationTime) } catch { $created = $null } [pscustomobject]@{ SequenceNumber = $point.SequenceNumber Description = $point.Description CreationTime = $created RestorePointType = $point.RestorePointType } } $pointRows = $pointRows | Sort-Object CreationTime -Descending $latest = $pointRows | Select-Object -First 1 $latestTime = $null $ageDays = $null $status = 'Нет точек' if ($latest -and $latest.CreationTime) { $latestTime = $latest.CreationTime $ageDays = [int]((Get-Date) - $latestTime).TotalDays if ($ageDays -gt $MaxAgeDays) { $status = 'Старая' } else { $status = 'OK' } } $shadows = @() try { $shadows = @(Get-CimInstance -ClassName Win32_ShadowCopy -ErrorAction Stop | Select-Object ID, VolumeName, InstallDate, State) } catch { $shadows = @() } $result = [pscustomobject]@{ MaxAgeDays = $MaxAgeDays Status = $status LatestCreationTime = $latestTime LatestAgeDays = $ageDays Points = @($pointRows) ShadowCopies = @($shadows) } if ($Json) { $text = $result | ConvertTo-Json -Depth 5 } else { $text = @() $text += "Статус: $status" $text += "Порог: $MaxAgeDays дней, возраст последней точки: $ageDays дней" if (@($pointRows).Count -eq 0) { $text += 'Точки восстановления не найдены или нет прав.' } else { $text += ($pointRows | Format-Table -AutoSize | Out-String -Width 240) } $text += "Теневых копий: $(@($shadows).Count)" $text = $text -join [Environment]::NewLine } if ($OutputPath) { $text | Set-Content -LiteralPath $OutputPath -Encoding UTF8 Write-Host "Отчёт сохранён: $OutputPath" } else { $text }