Back to Resources
Level
Script
Maintenance
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 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.
1<#
2This resource is provided as a convenience for Level users. We cannot
3guarantee it will work in all environments. Please test before deploying
4to your production environment. We welcome contributions to our community
5library
6
7Level Library
8https://level.io/library/script-windows-create-restore-point
9#>
10
11# Define the restore point name
12$restorePointName = "{{RestorePointName}} - " + (Get-Date -Format "yyyy-MM-dd HH:mm:ss")
13
14# Function to check and enable System Restore
15function Enable-SystemRestore {
16 $restoreEnabled = Get-ComputerRestorePoint -ErrorAction SilentlyContinue
17 if (-not $restoreEnabled) {
18 Write-Host "Enabling System Restore on C: drive..."
19 Enable-ComputerRestore -Drive "C:\"
20 }
21}
22
23# Function to check and start Volume Shadow Copy Service (VSS)
24function Start-VSSService {
25 $vssService = Get-Service -Name "VSS" -ErrorAction SilentlyContinue
26 if ($vssService -and $vssService.Status -ne "Running") {
27 Write-Host "Starting Volume Shadow Copy Service..."
28 Start-Service -Name "VSS"
29 }
30}
31
32# Function to modify restore point frequency limit
33function Modify-RestoreFrequency {
34 $restoreFreqPath = "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\SystemRestore"
35 $restoreFreqKey = "SystemRestorePointCreationFrequency"
36
37 $currentValue = (Get-ItemProperty -Path $restoreFreqPath -Name $restoreFreqKey -ErrorAction SilentlyContinue).$restoreFreqKey
38 if ($currentValue -ne 0) {
39 Write-Host "Adjusting restore point frequency limit..."
40 Set-ItemProperty -Path $restoreFreqPath -Name $restoreFreqKey -Value 0
41 }
42}
43
44# Run the checks and adjustments
45Enable-SystemRestore
46Start-VSSService
47Modify-RestoreFrequency
48
49# Attempt to create the restore point
50try {
51 Checkpoint-Computer -Description $restorePointName -RestorePointType 'MODIFY_SETTINGS' -ErrorAction Stop
52 Write-Host "System Restore Point created successfully with name: $restorePointName"
53 exit 0
54}
55catch {
56 Write-Host "ERROR: Failed to create System Restore Point. Details: $_"
57 exit 1
58}
59
Windows - Create Restore Point
This PowerShell script creates a system restore point with a dynamic name that combines a custom field {{RestorePointName}} with the current timestamp in "yyyy-MM-dd HH:mm:ss" format. The script attempts to create the restore point using the Checkpoint-Computer cmdlet with the type 'MODIFY_SETTINGS', and then provides feedback by writing to the console whether the operation was successful (exiting with code 0) or failed (exiting with code 1).
PowerShell
100
Local system
Explore more automations, scripts, and policies to further enhance your IT operations.