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 549a4e6d4b7..c490f9e7a64 100644 --- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -1016,10 +1016,11 @@ private static IEnumerable ViewsOf_System_Management_Autom CustomControl.Create(outOfBand: true) .StartEntry() .AddScriptBlockExpressionBinding(@" + $errorColor = '' + $commandPrefix = '' if (@('NativeCommandErrorMessage','NativeCommandError') -notcontains $_.FullyQualifiedErrorId -and @('CategoryView','ConciseView','DetailedView') -notcontains $ErrorView) { $myinv = $_.InvocationInfo - $errorColor = '' if ($Host.UI.SupportsVirtualTerminal) { $errorColor = $PSStyle.Formatting.Error } @@ -1070,10 +1071,7 @@ private static IEnumerable ViewsOf_System_Management_Autom } } - if ($commandPrefix) - { - $errorColor + $commandPrefix - } + $errorColor + $commandPrefix ") .AddScriptBlockExpressionBinding(@" Set-StrictMode -Off diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Error.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Error.Tests.ps1 index 624649fdfc4..1d89bf6c1fa 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Error.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Error.Tests.ps1 @@ -145,4 +145,9 @@ Describe 'Get-Error tests' -Tag CI { } } } + + It 'Get-Error works with strict mode' { + $out = pwsh -noprofile -command 'Set-StrictMode -Version Latest; $PSStyle.OutputRendering = "PlainText"; 1/0; Get-Error' | Out-String + $out | Should -Match "Message : Attempted to divide by zero." + } }