Show-ConsoleError
Shows errors and exceptions readably: type, message, position, script stack, frames and inner errors.
Syntax
Show-ConsoleError
[-AsString]
[-AsWidget]
[-Compact]
[[-InputObject] <Object>]
[-MaxFrames <Int32>]
[-NoStack]
[-ShowFrameworkFrames]
[-Width <Int32>]
[<CommonParameters>]#All Parameter SetsDescription
Takes ErrorRecords (from $Error, $_ in a catch block, -ErrorVariable) and .NET exceptions from the pipeline. Each shows the type and the message, the category and error id, PowerShell's position message with the failing line, the script stack, the .NET frames as Type.Method() with shortened paths and file:line links, framework frames collapsed into "+n framework frames", and the inner exceptions as "Caused by". With -AsWidget the views are returned for New-ConsolePanel, dashboards or Export-ConsoleFrame instead of written. Redirected output is plain text.
Examples
Example 1
$Error[0] | Show-ConsoleErrorThe last error
Example 2
try { Get-Item C:\missing -ErrorAction Stop } catch { $_ | Show-ConsoleError -ShowFrameworkFrames }In a catch block, with the framework frames
Parameters
- -AsString SwitchParameter
- Writes the view as one string of plain text instead of drawing it, to keep it in a variable or a file from any script, function or PowerShell version. Without it, PowerShell 7.2+ captures a view typed at the prompt ($x = ..., > file, Out-File); inside scripts and functions, and on Windows PowerShell 5.1, the view is drawn on the screen. Piped into another command (Out-Host, Out-String, Select-String) the view goes on as plain lines, without colour. Cannot be combined with -PassThru.
- -AsWidget SwitchParameter
- Returns the views instead of writing them.
- -Compact SwitchParameter
- Uses the message-first everyday error layout, highlighted invocation and folded inner exceptions. Stacks remain hidden unless -ShowFrameworkFrames is requested.
- -InputObject Object
- An ErrorRecord, an exception or a message (pipeline input).
- -MaxFrames Int32
- The most app frames shown per error (default 8).
- -NoStack SwitchParameter
- Leaves out the stack frames: type, message and position only.
- -ShowFrameworkFrames SwitchParameter
- Shows framework frames (System, Microsoft, the PowerShell engine) instead of collapsing them.
- -Width Int32
- Lays the output out for this width instead of the terminal's.
Common Parameters
This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters.