Problem overview
System changes—like software updates, security modifications, or configuration adjustments—can sometimes lead to unintended issues. Having a reliable rollback option is essential for IT professionals and MSPs managing multiple endpoints. This script ensures a System Restore Point is created proactively, providing a safety net for reverting to a stable system state when necessary.
<#
This resource is provided as a convenience for Level users. We cannot
guarantee it will work in all environments. Please test before deploying
to your production environment. We welcome contributions to our community
library
Level Library
https://level.io/library/script-windows-create-restore-point
#>
# Define the restore point name
$restorePointName = "{{RestorePointName}} - " + (Get-Date -Format "yyyy-MM-dd HH:mm:ss")
# Function to check and enable System Restore
function Enable-SystemRestore {
$restoreEnabled = Get-ComputerRestorePoint -ErrorAction SilentlyContinue
if (-not $restoreEnabled) {
Write-Host "Enabling System Restore on C: drive..."
Enable-ComputerRestore -Drive "C:\"
}
}
# Function to check and start Volume Shadow Copy Service (VSS)
function Start-VSSService {
$vssService = Get-Service -Name "VSS" -ErrorAction SilentlyContinue
if ($vssService -and $vssService.Status -ne "Running") {
Write-Host "Starting Volume Shadow Copy Service..."
Start-Service -Name "VSS"
}
}
# Function to modify restore point frequency limit
function Modify-RestoreFrequency {
$restoreFreqPath = "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\SystemRestore"
$restoreFreqKey = "SystemRestorePointCreationFrequency"
$currentValue = (Get-ItemProperty -Path $restoreFreqPath -Name $restoreFreqKey -ErrorAction SilentlyContinue).$restoreFreqKey
if ($currentValue -ne 0) {
Write-Host "Adjusting restore point frequency limit..."
Set-ItemProperty -Path $restoreFreqPath -Name $restoreFreqKey -Value 0
}
}
# Run the checks and adjustments
Enable-SystemRestore
Start-VSSService
Modify-RestoreFrequency
# Attempt to create the restore point
try {
Checkpoint-Computer -Description $restorePointName -RestorePointType 'MODIFY_SETTINGS' -ErrorAction Stop
Write-Host "System Restore Point created successfully with name: $restorePointName"
exit 0
}
catch {
Write-Host "ERROR: Failed to create System Restore Point. Details: $_"
exit 1
}
This PowerShell script generates a System Restore Point in Windows using the built-in Checkpoint-Computer command. The restore point is named dynamically with a timestamp for easy identification. When executed, it verifies if the restore point was successfully created, providing a confirmation message upon success or an error message if the operation fails.
Use cases
- Automatically create restore points before patching via a Level Automation.
- Generate restore points before modifying system configurations.
- Implement scheduled restore points as part of a weekly security or maintenance task.
- Run on-demand before deploying major application updates or drivers.
Recommendations
- Schedule via Level Automations: Run this script before patching cycles, software updates, or security audits.
- Test before deployment: Run manually on a test machine to confirm proper restore point creation.
- Ensure System Restore is enabled: This script relies on Windows’ System Restore feature being active.
- Name consistency: Use clear, structured naming conventions to identify restore points easily.