Don't allow undo in combination with deployment-targeted parameters

This commit is contained in:
Raphire
2026-03-23 21:03:22 +01:00
parent bc8fc1a284
commit b1cf364c7d

View File

@@ -334,8 +334,16 @@ foreach ($Param in $script:ControlParams) {
}
}
# Guard: Undo mode requires at least one actionable, non-control parameter.
# Guard: Undo mode requires at least one actionable and cannot be combined with deployment-targeted parameters
if ($script:Params.ContainsKey('Undo')) {
$deploymentTargetParams = @('Sysprep', 'User', 'AppRemovalTarget')
$selectedDeploymentParams = @($deploymentTargetParams | Where-Object { $script:Params.ContainsKey($_) })
if ($selectedDeploymentParams.Count -gt 0) {
Write-Error "The -Undo parameter cannot be combined with deployment target parameters: -$($selectedDeploymentParams -join ', -')."
AwaitKeyToExit
}
$loadsSettingsFromPreset = $RunDefaults -or $RunDefaultsLite -or $RunSavedSettings
$undoTargets = @($script:Params.Keys | Where-Object {
($script:ControlParams -notcontains $_) -and $_ -ne 'Apps' -and $_ -ne 'CreateRestorePoint'