fix: correct error message formatting in Convert-RegistryKeyToSnapshot and update tests for SkipRegistryBackup

This commit is contained in:
Jeffrey 2026-07-19 23:57:14 +02:00
parent 83466219eb
commit 9f10bc56ff
No known key found for this signature in database
4 changed files with 15 additions and 2 deletions

View File

@ -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 {

View File

@ -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
}
}

View File

@ -0,0 +1,6 @@
{
"Version": "1.0",
"Deployment": [
{ "Name": "SkipRegistryBackup", "Value": true }
]
}

View File

@ -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
}