diff --git a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs
index b29fe0bb5d..d466663631 100644
--- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs
+++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs
@@ -996,7 +996,7 @@ namespace System.Management.Automation.Runspaces
CustomControl.Create(outOfBand: true)
.StartEntry()
.AddScriptBlockExpressionBinding(@"
- if (@('NativeCommandErrorMessage','NativeCommandError') -notcontains $_.FullyQualifiedErrorId -and @('CategoryView','ConciseView') -notcontains $ErrorView)
+ if (@('NativeCommandErrorMessage','NativeCommandError') -notcontains $_.FullyQualifiedErrorId -and @('CategoryView','ConciseView','DetailedView') -notcontains $ErrorView)
{
$myinv = $_.InvocationInfo
if ($myinv -and $myinv.MyCommand)
@@ -1286,7 +1286,10 @@ namespace System.Management.Automation.Runspaces
else
{
$myinv = $err.InvocationInfo
- if ($ErrorView -eq 'ConciseView') {
+ if ($ErrorView -eq 'DetailedView') {
+ return (Get-Error | Out-String)
+ }
+ elseif ($ErrorView -eq 'ConciseView') {
$posmsg = Get-ConciseViewPositionMessage
}
elseif ($myinv -and ($myinv.MyCommand -or ($err.CategoryInfo.Category -ne 'ParserError'))) {
diff --git a/src/System.Management.Automation/engine/CommandBase.cs b/src/System.Management.Automation/engine/CommandBase.cs
index 2e1c5cda56..016b22ff59 100644
--- a/src/System.Management.Automation/engine/CommandBase.cs
+++ b/src/System.Management.Automation/engine/CommandBase.cs
@@ -300,6 +300,9 @@ namespace System.Management.Automation
/// Concise shows more information on the context of the error or just the message if not a script or parser error.
ConciseView = 2,
+
+ /// Detailed will leverage Get-Error to get much more detailed information for the error.
+ DetailedView = 3,
}
#endregion ErrorView
diff --git a/test/powershell/engine/Formatting/ErrorView.Tests.ps1 b/test/powershell/engine/Formatting/ErrorView.Tests.ps1
index b94c4b5fa4..21c886d5ae 100644
--- a/test/powershell/engine/Formatting/ErrorView.Tests.ps1
+++ b/test/powershell/engine/Formatting/ErrorView.Tests.ps1
@@ -170,4 +170,20 @@ Describe 'Tests for $ErrorView' -Tag CI {
$e | Should -BeLike '*Oops!*'
}
}
+
+ Context 'DetailedView tests' {
+
+ It 'Detailed error is rendered' {
+ try {
+ $ErrorView = 'DetailedView'
+ throw 'Oops!'
+ }
+ catch {
+ # an extra newline gets added by the formatting system so we remove them
+ $e = ($_ | Out-String).Trim([Environment]::NewLine.ToCharArray())
+ }
+
+ $e | Should -BeExactly (Get-Error | Out-String).Trim([Environment]::NewLine.ToCharArray())
+ }
+ }
}