2023-08-08 16:44:10 -05:00
|
|
|
function Set-WinUtilRestorePoint {
|
|
|
|
<#
|
|
|
|
|
2023-10-19 17:12:55 -05:00
|
|
|
.SYNOPSIS
|
|
|
|
Creates a Restore Point
|
|
|
|
|
|
|
|
#>
|
2023-08-08 16:44:10 -05:00
|
|
|
|
|
|
|
# Check if the user has administrative privileges
|
|
|
|
if (-Not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
|
|
|
Write-Host "Please run this script as an administrator."
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check if System Restore is enabled for the main drive
|
|
|
|
try {
|
|
|
|
# Try getting restore points to check if System Restore is enabled
|
|
|
|
Enable-ComputerRestore -Drive "$env:SystemDrive"
|
|
|
|
} catch {
|
|
|
|
Write-Host "An error occurred while enabling System Restore: $_"
|
|
|
|
}
|
|
|
|
|
2023-09-07 14:37:27 -05:00
|
|
|
# Check if the SystemRestorePointCreationFrequency value exists
|
|
|
|
$exists = Get-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -name "SystemRestorePointCreationFrequency" -ErrorAction SilentlyContinue
|
|
|
|
if($null -eq $exists){
|
|
|
|
write-host 'Changing system to allow multiple restore points per day'
|
2023-10-19 17:12:55 -05:00
|
|
|
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name "SystemRestorePointCreationFrequency" -Value "0" -Type DWord -Force -ErrorAction Stop | Out-Null
|
2023-09-07 14:37:27 -05:00
|
|
|
}
|
|
|
|
|
2023-08-08 16:44:10 -05:00
|
|
|
# Get all the restore points for the current day
|
|
|
|
$existingRestorePoints = Get-ComputerRestorePoint | Where-Object { $_.CreationTime.Date -eq (Get-Date).Date }
|
|
|
|
|
|
|
|
# Check if there is already a restore point created today
|
|
|
|
if ($existingRestorePoints.Count -eq 0) {
|
|
|
|
$description = "System Restore Point created by WinUtil"
|
2023-10-19 17:12:55 -05:00
|
|
|
|
2023-08-08 16:44:10 -05:00
|
|
|
Checkpoint-Computer -Description $description -RestorePointType "MODIFY_SETTINGS"
|
2023-09-07 14:37:27 -05:00
|
|
|
Write-Host -ForegroundColor Green "System Restore Point Created Successfully"
|
2023-08-08 16:44:10 -05:00
|
|
|
}
|
|
|
|
}
|