From 9f10bc56ff6aa6be03ee82397f8f64aea4bbddaa Mon Sep 17 00:00:00 2001 From: Jeffrey <9938813+Raphire@users.noreply.github.com> Date: Sun, 19 Jul 2026 23:57:14 +0200 Subject: [PATCH] fix: correct error message formatting in Convert-RegistryKeyToSnapshot and update tests for SkipRegistryBackup --- Scripts/Features/Backup-RegistrySnapshotCapture.ps1 | 2 +- Tests/Import-ConfigToParams.Tests.ps1 | 7 +++++++ .../JsonFileLoading/ExportedConfig.SkipRegistryBackup.json | 6 ++++++ Win11Debloat.ps1 | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 Tests/TestData/JsonFileLoading/ExportedConfig.SkipRegistryBackup.json diff --git a/Scripts/Features/Backup-RegistrySnapshotCapture.ps1 b/Scripts/Features/Backup-RegistrySnapshotCapture.ps1 index 110597c..1098dc6 100644 --- a/Scripts/Features/Backup-RegistrySnapshotCapture.ps1 +++ b/Scripts/Features/Backup-RegistrySnapshotCapture.ps1 @@ -242,7 +242,7 @@ function Convert-RegistryKeyToSnapshot { foreach ($subKeyName in @($RegistryKey.GetSubKeyNames())) { $childKey = $RegistryKey.OpenSubKey($subKeyName, $false) if ($null -eq $childKey) { - throw "Unable to read registry subkey '$($RegistryKey.Name)\\$subKeyName' while creating a backup snapshot. The backup was not created." + throw "Unable to read registry subkey '$($RegistryKey.Name)\$subKeyName' while creating a backup snapshot. The backup was not created." } try { diff --git a/Tests/Import-ConfigToParams.Tests.ps1 b/Tests/Import-ConfigToParams.Tests.ps1 index d7a37c8..93744af 100644 --- a/Tests/Import-ConfigToParams.Tests.ps1 +++ b/Tests/Import-ConfigToParams.Tests.ps1 @@ -3,6 +3,7 @@ BeforeAll { . (Join-Path $PSScriptRoot '..\Scripts\Helpers\Add-Parameter.ps1') . (Join-Path $PSScriptRoot '..\Scripts\Helpers\Import-ConfigToParams.ps1') $script:ConfigFixturePath = Join-Path $PSScriptRoot 'TestData\JsonFileLoading\ExportedConfig.WithSettings.json' + $script:SkipRegistryBackupFixturePath = Join-Path $PSScriptRoot 'TestData\JsonFileLoading\ExportedConfig.SkipRegistryBackup.json' } Describe 'Import-ConfigToParams' { @@ -36,4 +37,10 @@ Describe 'Import-ConfigToParams' { $script:Params.ContainsKey('User') | Should -BeFalse $script:Params.ContainsKey('AppRemovalTarget') | Should -BeFalse } + + It 'imports SkipRegistryBackup when deployment settings request it' { + Import-ConfigToParams -ConfigPath $script:SkipRegistryBackupFixturePath -CurrentBuild 22631 | Out-Null + + $script:Params['SkipRegistryBackup'] | Should -BeTrue + } } diff --git a/Tests/TestData/JsonFileLoading/ExportedConfig.SkipRegistryBackup.json b/Tests/TestData/JsonFileLoading/ExportedConfig.SkipRegistryBackup.json new file mode 100644 index 0000000..7a2489d --- /dev/null +++ b/Tests/TestData/JsonFileLoading/ExportedConfig.SkipRegistryBackup.json @@ -0,0 +1,6 @@ +{ + "Version": "1.0", + "Deployment": [ + { "Name": "SkipRegistryBackup", "Value": true } + ] +} diff --git a/Win11Debloat.ps1 b/Win11Debloat.ps1 index b0760bc..cae6112 100644 --- a/Win11Debloat.ps1 +++ b/Win11Debloat.ps1 @@ -556,7 +556,7 @@ else { # If the number of keys in ControlParams equals the number of keys in Params then no modifications/changes were selected # or added by the user, and the script can exit without making any changes. -if (($controlParamsCount -eq $script:Params.Keys.Count) -or ($script:Params.Keys.Count -eq 1 -and ($script:Params.Keys -contains 'CreateRestorePoint' -or $script:Params.Keys -contains 'SkipRegistryBackup' -or $script:Params.Keys -contains 'Apps'))) { +if (($controlParamsCount -eq $script:Params.Keys.Count) -or ($script:Params.Keys.Count -eq 1 -and ($script:Params.Keys -contains 'CreateRestorePoint' -or $script:Params.Keys -contains 'Apps'))) { Write-Output "The script completed without making any changes." Wait-ForKeyPress }