Remote sessions targeting Windows machines unexpectedly use ANSI character encoding for external programs
See original GitHub issueNote: It is debatable what console encoding should apply when remoting into a Window machine - the caller’s or the target machine’s - but (effectively) using ANSI encoding - rather than the OEM code page, as is still the default on Windows - seems like the wrong choice.
Curiously, Windows PowerShell behaves this way too.
Steps to reproduce
Run on (PS Core) on Windows:
- from an elevated session, to enable “loopback” remoting
- make sure that the calling version is enabled for remoting
& {
# Target the local machine.
$htParams = @{ ('HostName', 'ComputerName')[$env:OS -eq 'Windows_NT'] = '.' }
# On Windows, determine what edition / version to target remotely: use the caller's.
if ($env:OS -eq 'Windows_NT') {
$htParams['ConfigurationName'] = (('PowerShell.' + $PSVersionTable.PSVersion), 'microsoft.powershell')[$PSVersionTable.PSEdition -ne 'Core']
}
Invoke-Command @htParams { if ($env:OS -eq 'Windows_NT') { chcp } else { $env:LANG }; [Console]::InputEncoding.WebName; [Console]::OutputEncoding.WebName, $OutputEncoding.WebName }
}
Expected behavior
Active code page: 437
ibm437 # [Console]::InputEncoding.WebName
ibm437 # [Console]::OutputEncoding.WebName
utf-8 # $OutputEncoding
Actual behavior
Active code page: 437
windows-1252 # !! *ANSI* code page
Codepage - 0 # !! *0* - but in effect seems to behave like ANSI
utf-8
Environment data
PowerShell Core 7.2.0-preview.4
Issue Analytics
- State:
- Created 2 years ago
- Comments:61 (27 by maintainers)
Top Results From Across the Web
Change default code page of Windows console to UTF-8
To change the codepage for the console only, do the following: Start -> Run -> regedit; Go to [HKEY_LOCAL_MACHINE\Software\Microsoft\Command ...
Read more >about Character Encoding - PowerShell
Describes how PowerShell uses character encoding for input and output of string data.
Read more >Use a different character encoding
In this example scenario we will add support for using a different character encoding in the contents of SOAP requests. Out of the...
Read more >How to use character encoding classes in .NET
This article explains how to use the classes that .NET provides for encoding and decoding text by using various encoding schemes.
Read more >Character encoding on remote connections – strange ...
A character encoding determines which binary sequence is used to represent each letter, or other character. Many different ways to encode ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks all for sticking to this and working on a solution.
Thanks for the PR, I’ve been able to test it and can also confirm it fixes this particular problem. I also couldn’t find any side affects and things acted like they did before.