← All scripts

Windows configuration

Enable System Restore + Restore Point

Enables System Restore on the system drive and creates a restore point.

Download .ps199 lines · PowerShell

Replace generic placeholder values (tenant, domain, secrets) for your own environment before running. Read it first and test safely.

# RMM PowerShell Component
# Ensure System Restore enabled on C: and create a restore point (bypasses 24h throttle)
# Exit codes: 0 = success, 1 = failure

$ErrorActionPreference = 'Stop'

$Drive = "C:\"
$DriveLetter = "C:"
$RestorePointDescription = "RMM - Restore point"
$RestorePointType = "MODIFY_SETTINGS"

function Write-Log {
    param([string]$Message)
    $ts = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    Write-Output "[$ts] $Message"
}

function Ensure-RestorePointThrottleDisabled {
    $base = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore"
    if (-not (Test-Path $base)) {
        New-Item -Path $base -Force | Out-Null
    }
    New-ItemProperty -Path $base -Name "SystemRestorePointCreationFrequency" -PropertyType DWord -Value 0 -Force | Out-Null
    Write-Log "Set SystemRestorePointCreationFrequency=0 (disable 24h throttle)."
}

function Ensure-VSSServices {
    foreach ($svcName in @("VSS","swprv")) {
        $svc = Get-Service -Name $svcName -ErrorAction SilentlyContinue
        if ($null -eq $svc) { continue }
        if ($svc.StartType -eq 'Disabled') {
            Write-Log "$svcName is Disabled; setting to Manual."
            Set-Service -Name $svcName -StartupType Manual
        }
        if ($svc.Status -ne 'Running') {
            Write-Log "Starting $svcName."
            Start-Service -Name $svcName
        }
    }
}

function Confirm-SystemRestoreWorks {
    # Best practical confirmation: can we enumerate restore points without error?
    try {
        $null = Get-ComputerRestorePoint -ErrorAction Stop
        return $true
    } catch {
        return $false
    }
}

try {
    Write-Log "Starting System Restore enforcement on $Drive"

    # Enable if needed (idempotent)
    if (-not (Confirm-SystemRestoreWorks)) {
        Write-Log "System Restore query failed. Attempting to enable on $Drive..."
        Enable-ComputerRestore -Drive $Drive
        Start-Sleep -Seconds 2

        if (-not (Confirm-SystemRestoreWorks)) {
            throw "Failed to confirm System Restore after enabling on $Drive."
        }
        Write-Log "System Restore enabled on $Drive"
    } else {
        Write-Log "System Restore appears enabled on $Drive"
    }

    Ensure-VSSServices
    Ensure-RestorePointThrottleDisabled

    # Capture current latest restore point timestamp/seq (for verification)
    $before = $null
    try {
        $before = Get-ComputerRestorePoint | Sort-Object CreationTime -Descending | Select-Object -First 1
    } catch { }

    Write-Log "Creating restore point: '$RestorePointDescription'"
    Checkpoint-Computer -Description $RestorePointDescription -RestorePointType $RestorePointType

    Start-Sleep -Seconds 2

    $after = Get-ComputerRestorePoint | Sort-Object CreationTime -Descending | Select-Object -First 1
    if (-not $after) {
        throw "Restore point creation ran, but no restore points were returned."
    }

    if ($before -and ($after.SequenceNumber -eq $before.SequenceNumber)) {
        throw "Restore point creation did not produce a new restore point (sequence number unchanged)."
    }

    Write-Log ("Latest restore point: {0} | Seq {1} | {2}" -f $after.CreationTime, $after.SequenceNumber, $after.Description)
    Write-Log "Done."
    exit 0
}
catch {
    Write-Log "ERROR: $($_.Exception.Message)"
    exit 1
}