diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/out-printer/PrinterLineOutput.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/out-printer/PrinterLineOutput.cs
index cbd19a17f4..94f3fe6a50 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/out-printer/PrinterLineOutput.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/out-printer/PrinterLineOutput.cs
@@ -5,6 +5,8 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
+using System.Management.Automation;
+using System.Management.Automation.Internal;
namespace Microsoft.PowerShell.Commands.Internal.Format
{
@@ -62,11 +64,25 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
internal override void WriteLine(string s)
{
CheckStopProcessing();
- // delegate the action to the helper,
- // that will properly break the string into
- // screen lines
- _writeLineHelper.WriteLine(s, this.ColumnNumber);
+
+ // Remove all ANSI escape sequences before sending out to the printer.
+ s = new ValueStringDecorated(s).ToString(OutputRendering.PlainText);
+ WriteRawText(s);
}
+
+ ///
+ /// Write a raw text by delegating to the writer underneath, with no change to the text.
+ /// For example, keeping VT escape sequences intact in it.
+ ///
+ /// The raw text to be written to the device.
+ internal override void WriteRawText(string s)
+ {
+ CheckStopProcessing();
+
+ // Delegate the action to the helper, that will properly break the string into screen lines.
+ _writeLineHelper.WriteLine(s, ColumnNumber);
+ }
+
#endregion
///