Comprehensive Windows System Restore Point management script with automated creation, monitoring, email notifications, and logging.
- ✅ Automated Configuration - Enables and configures System Restore with customizable disk space allocation (8-10%)
- ✅ Configurable Creation Frequency - Sets Windows registry to allow restore points every 2 hours (default) instead of 24 hours
- ✅ Automatic Scheduled Task Creation - Creates Windows Scheduled Task automatically during configuration
- ✅ Initial Restore Point - Creates an initial restore point immediately after configuration
- ✅ Scheduled Creation - Creates restore points automatically on a configurable schedule (default: daily)
- ✅ Intelligent Maintenance - Maintains a minimum number of restore points (default: 10)
- ✅ Email Notifications - Sends notifications when restore points are created, deleted, or applied
- ✅ Comprehensive Logging - Logs all activities to centralized markdown log files (
C:\mytech.today\logs\) - ✅ Error Handling - Robust error handling with fallback mechanisms
- ✅ Task Status Monitoring - View scheduled task status with
-Action List - ✅ Scriptable - Can be triggered by other scripts for automated workflows
- PowerShell: 5.1 or later
- Operating System: Windows 10, Windows 11, Windows Server 2016/2019/2022
- Privileges: Administrator rights required
- Modules: No external modules required (uses built-in cmdlets)
- Clone or download the repository:
git clone https://github.com/mytech-today-now/PowerShellScripts.git
cd PowerShellScripts/RestorePoints- Review and customize the configuration file:
notepad config.json- Run the script with administrator privileges to configure System Restore:
.\Manage-RestorePoints.ps1 -Action ConfigureThis will:
- Enable System Restore on the system drive
- Configure disk space allocation (default: 10%)
- Create an initial restore point
- Set up a Windows Scheduled Task for automatic monitoring (runs daily by default)
- Send email notification (if configured)
The script uses a JSON configuration file (config.json) with the following structure:
{
"RestorePoint": {
"DiskSpacePercent": 10,
"MinimumCount": 10,
"MaximumCount": 20,
"CreateOnSchedule": true,
"ScheduleIntervalMinutes": 1440
},
"Email": {
"Enabled": false,
"SmtpServer": "smtp.example.com",
"SmtpPort": 587,
"UseSsl": true,
"From": "restorepoint@example.com",
"To": ["admin@example.com"],
"Username": "",
"PasswordEncrypted": ""
},
"Logging": {
"LogPath": "Logs\\RestorePoint.log",
"MaxLogSizeMB": 10,
"RetentionDays": 30
}
}- DiskSpacePercent (8-100): Percentage of disk space allocated for restore points
- MinimumCount (1-100): Minimum number of restore points to maintain
- MaximumCount (1-100): Maximum number of restore points before cleanup
- CreateOnSchedule (true/false): Enable automatic restore point creation
- ScheduleIntervalMinutes (1-43200): Interval between automatic restore points (in minutes)
- CreationFrequencyMinutes (1-1440): Minimum time interval (in minutes) between restore point creation. Default Windows value is 1440 (24 hours). Recommended: 120 (2 hours) for more frequent protection
- Enabled (true/false): Enable email notifications
- SmtpServer: SMTP server address
- SmtpPort: SMTP server port (typically 587 for TLS, 25 for non-TLS)
- UseSsl (true/false): Use SSL/TLS encryption
- From: Sender email address
- To: Array of recipient email addresses
- Username: SMTP authentication username (optional)
- PasswordEncrypted: Encrypted password (use
ConvertFrom-SecureString)
Note: This script follows myTech.Today standards and logs to C:\mytech.today\logs\ regardless of the config.json LogPath setting. Logs are written in markdown format with monthly rotation.
- LogPath: (Deprecated - logs now written to
C:\mytech.today\logs\Manage-RestorePoints-yyyy-MM.md) - MaxLogSizeMB: Maximum log file size before archiving
- RetentionDays: Number of days to retain archived logs
Log File Location:
- All logs are written to:
C:\mytech.today\logs\ - Log file name format:
Manage-RestorePoints-yyyy-MM.md(e.g.,Manage-RestorePoints-2025-10.md) - Logs are in markdown table format with icons (ℹ️ INFO,
⚠️ WARNING, ❌ ERROR, ✅ SUCCESS) - Monthly rotation - one file per month
- Logs are never overwritten, always appended
To encrypt your email password for the configuration file:
# Create encrypted password
$password = Read-Host "Enter SMTP password" -AsSecureString
$encryptedPassword = ConvertFrom-SecureString $password
# Update config.json with the encrypted password
$config = Get-Content config.json | ConvertFrom-Json
$config.Email.PasswordEncrypted = $encryptedPassword
$config | ConvertTo-Json -Depth 10 | Set-Content config.json.\Manage-RestorePoints.ps1 [-Action <String>] [-ConfigPath <String>] [-Description <String>] [-Force]-
Action (Configure | Create | List | Cleanup | Monitor)
Configure: Configures System Restore settingsCreate: Creates a new restore pointList: Lists all available restore pointsCleanup: Performs cleanup of old restore pointsMonitor: Monitors and maintains restore points (default)
-
ConfigPath (optional): Path to custom configuration file
-
Description (optional): Description for the restore point (used with
-Action Create) -
Force (optional): Force creation even if a recent restore point exists
# Configure System Restore with default settings
.\Manage-RestorePoints.ps1 -Action Configure
# Configure with custom config file
.\Manage-RestorePoints.ps1 -Action Configure -ConfigPath "C:\Config\custom-config.json"# Create restore point with default description
.\Manage-RestorePoints.ps1 -Action Create
# Create restore point with custom description
.\Manage-RestorePoints.ps1 -Action Create -Description "Pre-Windows Update"
# Force creation even if recent restore point exists
.\Manage-RestorePoints.ps1 -Action Create -Description "Critical Backup" -Force# List all available restore points
.\Manage-RestorePoints.ps1 -Action List# Manually trigger cleanup
.\Manage-RestorePoints.ps1 -Action Cleanup# Run monitoring (creates restore points on schedule, performs cleanup)
.\Manage-RestorePoints.ps1 -Action Monitor
# This is the default action, so you can also just run:
.\Manage-RestorePoints.ps1The script automatically creates a Windows Scheduled Task when you run:
.\Manage-RestorePoints.ps1 -Action ConfigureThis creates a scheduled task at:
- Task Path:
\myTech.Today\ - Task Name:
System Restore Point - Daily Monitoring - Schedule: Configurable via
ScheduleIntervalMinutesin config.json (default: daily at midnight) - Runs As: SYSTEM account with highest privileges
- Action: Executes the script with
-Action Monitor
Note: All myTech.Today scripts create scheduled tasks in the \myTech.Today\ folder for easy management.
# View task status along with restore points
.\Manage-RestorePoints.ps1 -Action ListThis displays:
- Task state (Ready, Running, Disabled)
- Last run time and result
- Next scheduled run time
- Trigger details
If you need to manually create a scheduled task with custom settings:
# Create scheduled task with custom interval (e.g., every 6 hours)
$action = New-ScheduledTaskAction -Execute 'PowerShell.exe' `
-Argument '-NoProfile -ExecutionPolicy Bypass -File "C:\Path\To\Manage-RestorePoints.ps1" -Action Monitor'
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Hours 6) -RepetitionDuration ([TimeSpan]::MaxValue)
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
$settings = New-ScheduledTaskSettings -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable
Register-ScheduledTask -TaskName "Custom Restore Point Task" `
-TaskPath "\MyTasks\" `
-Action $action `
-Trigger $trigger `
-Principal $principal `
-Settings $settings `
-Description "Custom System Restore Point management"- Open Task Scheduler (
taskschd.msc) - Create Basic Task
- Name: "Manage Restore Points"
- Trigger: Daily (or your preferred schedule)
- Action: Start a program
- Program:
PowerShell.exe - Arguments:
-ExecutionPolicy Bypass -File "C:\Path\To\Manage-RestorePoints.ps1" -Action Monitor
- Program:
- Check "Run with highest privileges"
You can call this script from other automation scripts:
# Example: Create restore point before software installation
& "C:\Scripts\Manage-RestorePoints.ps1" -Action Create -Description "Pre-Software Install" -Force
# Install software
Install-Software.ps1
# Verify installation
if ($LASTEXITCODE -eq 0) {
Write-Host "Installation successful"
} else {
Write-Host "Installation failed - restore point available for rollback"
}All script activities are logged to the file specified in the configuration. Log entries include:
- Timestamp
- Log level (INFO, WARNING, ERROR, SUCCESS)
- Detailed message
Example log output:
[2025-01-15 10:30:00] [INFO] === Manage-RestorePoints.ps1 v1.0.0 Started ===
[2025-01-15 10:30:00] [INFO] Action: Monitor
[2025-01-15 10:30:01] [INFO] Configuration loaded from config.json
[2025-01-15 10:30:01] [INFO] Starting restore point monitoring
[2025-01-15 10:30:02] [INFO] Current restore point count: 8 (Minimum: 10)
[2025-01-15 10:30:02] [WARNING] No restore points exist. Creating initial restore point.
[2025-01-15 10:30:05] [SUCCESS] Restore point created successfully: Scheduled Restore Point - 2025-01-15 10:30:02
[2025-01-15 10:30:05] [INFO] === Manage-RestorePoints.ps1 Completed ===
When email notifications are enabled, the script sends HTML-formatted emails for the following events:
- Subject: "Restore Point Created - [COMPUTERNAME]"
- Includes: Computer name, date/time, description, status
- Subject: "Restore Point Deleted - [COMPUTERNAME]"
- Includes: Computer name, date/time, description, creation date, reason
- Subject: "System Restore Configured - [COMPUTERNAME]"
- Includes: Computer name, date/time, disk space allocated, status
Error: "This script requires administrator privileges"
Solution: Run PowerShell as Administrator or run the script with elevated privileges
Error: "System Restore is not enabled"
Solution: Run with -Action Configure to enable and configure System Restore
Error: "A restore point was created X hours ago"
Solution: Use the -Force parameter to override the 24-hour Windows limitation
Error: "Failed to send email notification"
Solutions:
- Verify SMTP server settings in config.json
- Check firewall rules for SMTP port
- Verify credentials (username/password)
- Test SMTP connectivity:
Test-NetConnection -ComputerName smtp.server.com -Port 587
Error: Log file path not accessible
Solution: Ensure the log directory exists and the script has write permissions
The script includes comprehensive Pester tests for quality assurance.
# Install Pester if not already installed
Install-Module -Name Pester -Force -SkipPublisherCheck
# Run tests
Invoke-Pester -Path .\Tests\Manage-RestorePoints.Tests.ps1
# Run tests with code coverage
$config = New-PesterConfiguration
$config.Run.Path = '.\Tests\Manage-RestorePoints.Tests.ps1'
$config.CodeCoverage.Enabled = $true
$config.CodeCoverage.Path = '.\Manage-RestorePoints.ps1'
Invoke-Pester -Configuration $config- Initial release
- System Restore configuration
- Automated restore point creation
- Email notifications
- Comprehensive logging
- Scheduled task support
- Error handling and fallback mechanisms
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch
- Write tests for new functionality
- Ensure all tests pass
- Submit a pull request
See LICENSE file in the repository root.
For issues, questions, or contributions:
- GitHub Issues: https://github.com/mytech-today-now/PowerShellScripts/issues
- Documentation: See
.augment/folder for development guidelines
PowerShell Scripts Project https://github.com/mytech-today-now/PowerShellScripts