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 906263225f4..03414836b6d 100644 --- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -742,7 +742,7 @@ private static IEnumerable ViewsOf_System_Management_Autom CustomControl.Create(outOfBand: true) .StartEntry() .AddScriptBlockExpressionBinding(@" - if (@('NativeCommandErrorMessage'.'NativeCommandError') -notcontains $_.FullyQualifiedErrorId -and @('CategoryView','ConciseView') -notcontains $ErrorView) + if (@('NativeCommandErrorMessage','NativeCommandError') -notcontains $_.FullyQualifiedErrorId -and @('CategoryView','ConciseView') -notcontains $ErrorView) { $myinv = $_.InvocationInfo if ($myinv -and $myinv.MyCommand) @@ -795,6 +795,7 @@ private static IEnumerable ViewsOf_System_Management_Autom .AddScriptBlockExpressionBinding(@" function Get-ConciseViewPositionMessage { + Set-StrictMode -Off $resetColor = '' if ($Host.UI.SupportsVirtualTerminal) { @@ -880,7 +881,7 @@ function Get-ConciseViewPositionMessage { if ($myinv -and $myinv.ScriptName -or $_.CategoryInfo.Category -eq 'ParserError') { if ($myinv.ScriptName) { - $posmsg = ""error in${resetcolor} $($myinv.ScriptName)${newline}"" + $posmsg = ""${resetcolor}$($myinv.ScriptName)${newline}"" } else { $posmsg = ""${newline}"" @@ -901,8 +902,12 @@ function Get-ConciseViewPositionMessage { $line = $myinv.Line $highlightLine = $myinv.PositionMessage.Split('+').Count - 1 $offsetLength = $myinv.PositionMessage.split('+')[$highlightLine].Trim().Length - $line = $line.Insert($myinv.OffsetInLine - 1 + $offsetLength, $resetColor) - $line = $line.Insert($myinv.OffsetInLine - 1, $errorColor) + + # don't color the whole line red + if ($offsetLength -lt $line.Length - 1) { + $line = $line.Insert($myinv.OffsetInLine - 1 + $offsetLength, $resetColor).Insert($myinv.OffsetInLine - 1, $accentColor) + } + $posmsg += ""${accentColor}${lineWhitespace}$($myinv.ScriptLineNumber) ${verticalBar} ${resetcolor}${line}`n"" $offsetWhitespace = ' ' * ($myinv.OffsetInLine - 1) $prefix = ""${accentColor}${headerWhitespace} ${verticalBar} ${errorColor}"" @@ -965,7 +970,7 @@ function Get-ConciseViewPositionMessage { elseif ($_.CategoryInfo.Category) { $reason = $_.CategoryInfo.Category } - elseif ($_CategoryInfo.Reason) { + elseif ($_.CategoryInfo.Reason) { $reason = $_.CategoryInfo.Reason }