Added option to create System Restore Point

This commit is contained in:
Raphire
2025-05-03 17:55:31 +02:00
parent fe2caec938
commit 83032ad1bc
3 changed files with 40 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ param (
[switch]$Verbose,
[switch]$Sysprep,
[string]$User,
[switch]$CreateRestorePoint,
[switch]$RunAppsListGenerator, [switch]$RunAppConfigurator,
[switch]$RunDefaults, [switch]$RunWin11Defaults,
[switch]$RunSavedSettings,

View File

@@ -317,11 +317,11 @@ The quick and advanced usage methods support switch parameters. A table of all t
| Parameter | Description |
| :-------: | ----------- |
| -CreateRestorePoint | Create a system restore point before making any changes. Unless a restore point was already created in the last 24 hours. |
| -Silent | Suppresses all interactive prompts, so the script will run without requiring any user input. |
| -Sysprep | Run the script in Sysprep mode. All changes will be applied to the Windows default user profile and will only affect new user accounts. |
| -User `<USERNAME>` | Run the script for the specified user, instead of the currently logged in user. This user must have logged on atleast once, and cannot be logged in at the time the script is run. |
| -RunDefaults | Run the script with the default settings. |
| -DisableFastStartup | Disables Fast Start-up to ensure a full shutdown. |
| -RunSavedSettings | Run the script with the saved custom settings from last time. These settings are saved to and read from the `SavedSettings` file in the root folder of the script. |
| -RemoveApps | Remove the default selection of bloatware apps. |
| -RemoveAppsCustom | Remove all apps specified in the 'CustomAppsList' file. IMPORTANT: You can generate your custom list by running the script with the `-RunAppsListGenerator` parameter. No apps will be removed if this file does not exist. |
@@ -344,6 +344,7 @@ The quick and advanced usage methods support switch parameters. A table of all t
| -RevertContextMenu | Restore the old Windows 10 style context menu. (Windows 11 only) |
| -DisableMouseAcceleration | Turn off Enhance Pointer Precision, also known as mouse acceleration. Requires reboot to apply. |
| -DisableStickyKeys | Disable the Sticky Keys keyboard shortcut. |
| -DisableFastStartup | Disables Fast Start-up to ensure a full shutdown. |
| -ShowHiddenFolders | Show hidden files, folders and drives. |
| -ShowKnownFileExt | Show file extensions for known file types. |
| -HideDupliDrive | Hide duplicate removable drive entries from the File Explorer navigation pane, so only the entry under 'This PC' remains. |

View File

@@ -5,6 +5,7 @@ param (
[switch]$Silent,
[switch]$Sysprep,
[string]$User,
[switch]$CreateRestorePoint,
[switch]$RunAppsListGenerator, [switch]$RunAppConfigurator,
[switch]$RunDefaults, [switch]$RunWin11Defaults,
[switch]$RunSavedSettings,
@@ -741,12 +742,42 @@ function GetUserName {
}
function CreateSystemRestorePoint {
Write-Output "> Creating system restore point..."
# Find existing restore points that are less than 24 hours old
try {
$recentRestorePoints = Get-ComputerRestorePoint | Where-Object { (Get-Date) - [System.Management.ManagementDateTimeConverter]::ToDateTime($_.CreationTime) -le (New-TimeSpan -Hours 24) }
} catch {
Write-Host "Error: Unable to retrieve existing restore points: $_" -ForegroundColor Red
Write-Output ""
return
}
if ($recentRestorePoints.Count -eq 0) {
Checkpoint-Computer -Description "Restore point created by Win11Debloat" -RestorePointType "MODIFY_SETTINGS"
Write-Output "System restore point created successfully"
}
else {
Write-Host "A recent restore point already exists, no new restore point was created." -ForegroundColor Yellow
}
Write-Output ""
}
function DisplayCustomModeOptions {
# Get current Windows build version to compare against features
$WinVersion = Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' CurrentBuild
PrintHeader 'Custom Mode'
if ($( Read-Host -Prompt "Do you wish to create a system restore point? (y/n)" ) -eq 'y') {
AddParameter 'CreateRestorePoint' 'Create a system restore point'
}
Write-Output ""
# Show options for removing apps, only continue on valid input
Do {
Write-Host "Options:" -ForegroundColor Yellow
@@ -1131,7 +1162,7 @@ $WinVersion = Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\Current
$global:Params = $PSBoundParameters
$global:FirstSelection = $true
$SPParams = 'WhatIf', 'Confirm', 'Verbose', 'Silent', 'Sysprep', 'Debug', 'User'
$SPParams = 'WhatIf', 'Confirm', 'Verbose', 'Silent', 'Sysprep', 'Debug', 'User', 'CreateRestorePoint'
$SPParamCount = 0
# Count how many SPParams exist within Params
@@ -1274,7 +1305,7 @@ if ((-not $global:Params.Count) -or $RunDefaults -or $RunWin11Defaults -or $RunS
Read-Host | Out-Null
}
$DefaultParameterNames = 'RemoveApps','DisableTelemetry','DisableBing','DisableLockscreenTips','DisableSuggestions','ShowKnownFileExt','DisableWidgets','HideChat','DisableCopilot','DisableFastStartup'
$DefaultParameterNames = 'CreateRestorePoint','RemoveApps','DisableTelemetry','DisableBing','DisableLockscreenTips','DisableSuggestions','ShowKnownFileExt','DisableWidgets','HideChat','DisableCopilot','DisableFastStartup'
PrintHeader 'Default Mode'
@@ -1381,6 +1412,10 @@ if ($SPParamCount -eq $global:Params.Keys.Count) {
else {
# Execute all selected/provided parameters
switch ($global:Params.Keys) {
'CreateRestorePoint' {
CreateSystemRestorePoint
continue
}
'RemoveApps' {
$appsList = ReadAppslistFromFile "$PSScriptRoot/Appslist.txt"
Write-Output "> Removing default selection of $($appsList.Count) apps..."