diff --git a/src/System.Management.Automation/commands/utility/FormatAndOutput/common/DefaultFormatters/PowerShellCore_format_ps1xml.cs b/src/System.Management.Automation/commands/utility/FormatAndOutput/common/DefaultFormatters/PowerShellCore_format_ps1xml.cs index 84c2d371a9..47dd76fabd 100644 --- a/src/System.Management.Automation/commands/utility/FormatAndOutput/common/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/commands/utility/FormatAndOutput/common/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -720,7 +720,7 @@ namespace System.Management.Automation.Runspaces CustomControl.Create(outOfBand: true) .StartEntry() .AddScriptBlockExpressionBinding(@" - if ($_.FullyQualifiedErrorId -ne ""NativeCommandErrorMessage"" -and $ErrorView -ne ""CategoryView"") + if (($_.FullyQualifiedErrorId -ne ""NativeCommandErrorMessage"" -and $_.FullyQualifiedErrorId -ne ""NativeCommandError"") -and $ErrorView -ne ""CategoryView"") { $myinv = $_.InvocationInfo if ($myinv -and $myinv.MyCommand) @@ -767,7 +767,7 @@ namespace System.Management.Automation.Runspaces } ") .AddScriptBlockExpressionBinding(@" - if ($_.FullyQualifiedErrorId -eq ""NativeCommandErrorMessage"") { + if ($_.FullyQualifiedErrorId -eq ""NativeCommandErrorMessage"" -or $_.FullyQualifiedErrorId -eq ""NativeCommandError"") { $_.Exception.Message } else diff --git a/src/System.Management.Automation/engine/NativeCommandProcessor.cs b/src/System.Management.Automation/engine/NativeCommandProcessor.cs index 507a5bb7ba..8971dd6446 100644 --- a/src/System.Management.Automation/engine/NativeCommandProcessor.cs +++ b/src/System.Management.Automation/engine/NativeCommandProcessor.cs @@ -1880,17 +1880,11 @@ namespace System.Management.Automation // // Wrap the rest of the output in ErrorRecords with the "NativeCommandErrorMessage" error ID // - char[] buffer = new char[4096]; - - int read = 0; - - while ((read = _streamReader.Read(buffer, 0, buffer.Length)) != 0) + while ((line = _streamReader.ReadLine()) != null) { - StringBuilder errorMessage = new StringBuilder().Append(buffer, 0, read); - AddObjectToWriter( new ErrorRecord( - new RemoteException(errorMessage.ToString()), + new RemoteException(line), "NativeCommandErrorMessage", ErrorCategory.NotSpecified, null),