Powershell: Get default system encoding
Asked Answered
H

2

23

The powershell cmdlet out-file has the switch -encoding witch you can set to default. This default value will use the encoding of the system's current ANSI code page.
My question is: How can I get the name of this default encoding that out-file will use with powershell?

Haskell answered 16/3, 2011 at 13:52 Comment(4)
I am not using default anymore. My experience is that "current ANSI code page" translates to "something that other programs are not really fond of except notepad", which I believe is a multibyte Unicode .Shupe
@Shupe I don't want to use default, but I have to. Normally I would use UTF8 or UTF16, but in this case I have some problems with legacy code.Haskell
@Oscaso : I wish you a better luck next time! There should be best practices forbidding the writing of legacy code from the start. I wonder why nobody did it yet :).Shupe
@Shupe Thanks! Let's hope so, by goodness!Haskell
P
37

Take a look at [System.Text.Encoding]::Default, I believe it is used as "default".

E.g. in my case:

[System.Text.Encoding]::Default.EncodingName

gets

Cyrillic (Windows)
Paresthesia answered 16/3, 2011 at 14:5 Comment(2)
That looks exactly like what i want. Thanks!Haskell
You can also use [System.Text.Encoding]::Default to get everthing.To
C
-1

I solved my problem with Windows Server 2012 and zabbix.exe->cmd.exe->Powershell.exe by using the following:

-old string:UserParameter=get.gost-pcidss.csv, powershell.exe -encodedCommand Yw....
-new string:UserParameter=get.gost-pcidss.csv,@chcp 65001>nul && powershell.exe -encodedCommand Yw....

In encodedCommand, I use chcp 65001; at the first line.

Caddis answered 15/3 at 10:8 Comment(1)
What? I don't understand what you are trying to say. Can you please clarify your answer?Haskell

© 2022 - 2024 — McMap. All rights reserved.