private/RestorePoint.ps1
|
function New-OctaRestorePoint { <# Constitution Principle I: attempts a System Restore Point before the first applied category each run. Checkpoint-Computer silently no-ops when throttled by Windows' 24h SystemRestorePointCreationFrequency, so the only reliable way to know whether a *new* point actually appeared is to compare Get-ComputerRestorePoint before/after (see research.md). Never throws - always returns a status the caller can act on. #> [CmdletBinding()] param( [switch]$NoRestorePoint, [string]$Description = 'Octa debloat run' ) if ($NoRestorePoint) { return [pscustomobject]@{ Status = 'SkippedByUser'; SequenceNumber = $null } } $before = @(Get-ComputerRestorePoint -ErrorAction SilentlyContinue | Select-Object -ExpandProperty SequenceNumber) try { Checkpoint-Computer -Description $Description -RestorePointType MODIFY_SETTINGS -ErrorAction Stop } catch { # Checkpoint-Computer throws when System Protection is off for the target volume. return [pscustomobject]@{ Status = 'SkippedProtectionDisabled'; SequenceNumber = $null } } $after = @(Get-ComputerRestorePoint -ErrorAction SilentlyContinue) $newPoint = $after | Where-Object { $_.SequenceNumber -notin $before } | Select-Object -Last 1 if ($newPoint) { return [pscustomobject]@{ Status = 'Created'; SequenceNumber = $newPoint.SequenceNumber } } # No error, but no new point appeared -> the 24h creation-frequency throttle suppressed it. return [pscustomobject]@{ Status = 'SkippedThrottled'; SequenceNumber = $null } } |