Powershell: Text encoding mismatch when 'Get-Member' output is piped to 'more'

Created on 2 Sep 2020  Â·  2Comments  Â·  Source: PowerShell/PowerShell

If you pipe the output of Get-Member to more, the ellipsis used to indicate truncation becomes garbled and is not rendered properly. Specifically, "…" becomes "ΓǪ".

Steps to reproduce

Run the following command in PowerShell v7.0.0+
Get-Process | Get-Member | more

Expected behavior

Expected behavior (sans pagination) can be seen by running Get-Process | Get-Member.

   TypeName: System.Diagnostics.Process

Name                       MemberType     Definition
----                       ----------     ----------
Handles                    AliasProperty  Handles = Handlecount
Name                       AliasProperty  Name = ProcessName
NPM                        AliasProperty  NPM = NonpagedSystemMemorySize64
PM                         AliasProperty  PM = PagedMemorySize64
SI                         AliasProperty  SI = SessionId
VM                         AliasProperty  VM = VirtualMemorySize64
WS                         AliasProperty  WS = WorkingSet64
Parent                     CodeProperty   System.Object Parent{get=GetParentProcess;}
Disposed                   Event          System.EventHandler Disposed(System.Object, System.EventArgs)
ErrorDataReceived          Event          System.Diagnostics.DataReceivedEventHandler ErrorDataReceived(Syst…
Exited                     Event          System.EventHandler Exited(System.Object, System.EventArgs)
OutputDataReceived         Event          System.Diagnostics.DataReceivedEventHandler OutputDataReceived(Sys…
BeginErrorReadLine         Method         void BeginErrorReadLine()
BeginOutputReadLine        Method         void BeginOutputReadLine()
CancelErrorRead            Method         void CancelErrorRead()
CancelOutputRead           Method         void CancelOutputRead()
-- More  --

Actual behavior

Note the rightmost characters in the definitions of ErrorDataReceived and OutputDataReceived.

   TypeName: System.Diagnostics.Process

Name                       MemberType     Definition
----                       ----------     ----------
Handles                    AliasProperty  Handles = Handlecount
Name                       AliasProperty  Name = ProcessName
NPM                        AliasProperty  NPM = NonpagedSystemMemorySize64
PM                         AliasProperty  PM = PagedMemorySize64
SI                         AliasProperty  SI = SessionId
VM                         AliasProperty  VM = VirtualMemorySize64
WS                         AliasProperty  WS = WorkingSet64
Parent                     CodeProperty   System.Object Parent{get=GetParentProcess;}
Disposed                   Event          System.EventHandler Disposed(System.Object, System.EventArgs)
ErrorDataReceived          Event          System.Diagnostics.DataReceivedEventHandler ErrorDataReceived(Syste…
Exited                     Event          System.EventHandler Exited(System.Object, System.EventArgs)
OutputDataReceived         Event          System.Diagnostics.DataReceivedEventHandler OutputDataReceived(Syst…
BeginErrorReadLine         Method         void BeginErrorReadLine()
BeginOutputReadLine        Method         void BeginOutputReadLine()
CancelErrorRead            Method         void CancelErrorRead()
CancelOutputRead           Method         void CancelOutputRead()
-- More  --

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Additionally, I was able to reproduce the issue on:

Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 6.2.9200
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0.}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Issue-Question Resolution-Answered

Most helpful comment

Unfortunately, more.com (which Windows PowerShell wraps in a more _function_) is a legacy console application that fundamentally does not support Unicode, only the legacy OEM code pages.

Thus, any characters outside the active OEM code page (run chcp) - such as … (HORIZONTAL ELLIPSIS, U+2026) - cannot be represented by more.com.

In the case of PowerShell Core, where $OutputEncoding now defaults to UTF-8, PowerShell sends UTF-8 bytes (3, in this case), which more.com then interprets as individual OEM characters, resulting in the symptom you're seeing:

# [char] 0x2026 is '…'
PSCore> [char] 0x2026 | more
…

The only workaround I know of is to use a modern pager application, which you can configure by assigning its path to $env:PAGER - see this SO answer for options.

All 2 comments

Unfortunately, more.com (which Windows PowerShell wraps in a more _function_) is a legacy console application that fundamentally does not support Unicode, only the legacy OEM code pages.

Thus, any characters outside the active OEM code page (run chcp) - such as … (HORIZONTAL ELLIPSIS, U+2026) - cannot be represented by more.com.

In the case of PowerShell Core, where $OutputEncoding now defaults to UTF-8, PowerShell sends UTF-8 bytes (3, in this case), which more.com then interprets as individual OEM characters, resulting in the symptom you're seeing:

# [char] 0x2026 is '…'
PSCore> [char] 0x2026 | more
…

The only workaround I know of is to use a modern pager application, which you can configure by assigning its path to $env:PAGER - see this SO answer for options.

This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.

Was this page helpful?
0 / 5 - 0 ratings