diff --git a/src/System.Management.Automation/engine/MshCommandRuntime.cs b/src/System.Management.Automation/engine/MshCommandRuntime.cs index be5ce9d3089..a948940ed7a 100644 --- a/src/System.Management.Automation/engine/MshCommandRuntime.cs +++ b/src/System.Management.Automation/engine/MshCommandRuntime.cs @@ -3212,13 +3212,6 @@ internal ActionPreference ErrorAction if (IsErrorActionSet) return _errorAction; - // Debug takes preference over Verbose - if (Debug) - return ActionPreference.Inquire; - if (Verbose) - return ActionPreference.Continue; - - // fall back to $ErrorAction if (!_isErrorActionPreferenceCached) { bool defaultUsed = false; diff --git a/test/powershell/Language/Scripting/ActionPreference.Tests.ps1 b/test/powershell/Language/Scripting/ActionPreference.Tests.ps1 index 091599af880..3edf8d8aae3 100644 --- a/test/powershell/Language/Scripting/ActionPreference.Tests.ps1 +++ b/test/powershell/Language/Scripting/ActionPreference.Tests.ps1 @@ -126,4 +126,23 @@ } $num | Should Be 2 } + + It ' does not take precedence over $ErrorActionPreference' -TestCases @( + @{switch="-Verbose"}, + @{switch="-Debug"} + ) { + param($switch) + $ErrorActionPreference = "SilentlyContinue" + $params = @{ + ItemType = "File"; + Path = "$testdrive\test.txt"; + Confirm = $false + } + New-Item @params > $null + $params += @{$switch=$true} + { New-Item @params } | Should Not Throw + $ErrorActionPreference = "Stop" + { New-Item @params } | ShouldBeErrorId "NewItemIOError,Microsoft.PowerShell.Commands.NewItemCommand" + Remove-Item "$testdrive\test.txt" -Force + } }