none
Windows PowerShell utf-8 encoding RRS feed

  • Question

  • Hello!

    I would like to know if it is possible to configure Windows PowerShell to print utf-8 characters?

    I searched the web and found multiple solutions, but nothing seems to be working.

    e.g.:

    * chcp 65001

    * $OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding

    I've also changed the font to "Lucida Console".

    sample file (List of languages): https://we.tl/t-KY9HIa8Nos 

    If I run the command Get-Content .\languages.txt I get square characters for certain languages.

    Best regards, Gasper

    Sunday, February 9, 2020 6:07 PM

All replies

  • I would like to know if it is possible to configure Windows PowerShell to print utf-8 characters?

    What do you mean with "print"? If you like to create files with a particular encoding most of the time you can use the parameter -Encoding. For example with Out-File or Export-Csv.

    You will have to be more specific about your issue.

    Ahhh ... and BTW: Get-Content has a parameter -Encoding as well!  ;-)


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    • Edited by BOfH-666 Sunday, February 9, 2020 7:09 PM
    Sunday, February 9, 2020 7:06 PM
  • PowerShell has no issues with UTF-8, UTF or Unicode and prints it just fine.  I suspect you are really asking about character set and not character encoding.  PowerShell uses the Windows standard character sets for each encoding.  The character set in use depends on the locale.  If you have a file encoded in a different charact5er set then you have to change teh character set and not the encoding.

    Also there are two encodings UTF8-BOM and UTF8.  Windows encode in UTF8 by default which is also known as ASCII.  UTF-BOM contains a byte order mark and a character set id.  Windows will automatically choose the correct character set for UTF8-BOM.  Unicode always contains a BOM.

    Character encoding: https://en.wikipedia.org/wiki/Character_encoding

    Character set: https://en.wikipedia.org/wiki/Category:Character_sets


    \_(ツ)_/



    • Edited by jrv Sunday, February 9, 2020 7:31 PM
    • Proposed as answer by BOfH-666 Sunday, February 9, 2020 11:47 PM
    Sunday, February 9, 2020 7:28 PM
  • Sorry, I don't know what would be the right term here, but when I run the Ge-Content command the console output should display utf8 characters. 

    That does not happen, certain character are just squares. If I open the same file in notepad++ I see all the characters. 

    Tuesday, February 11, 2020 11:38 AM
  • but when I run the Ge-Content command the console output should display utf8 characters.

    Did you try to use the parameter -Encoding (as I recommended already)??

    If not - do it please! And please try with different encodings.


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Tuesday, February 11, 2020 12:15 PM
  • Is it UTF-8 BOM?  If so then the BOM is specifying characters you don't have.  

    This is also a known issue with Notepad++.  Be sure you have the latest version as older versions did not handle UTF-8 correctly.

    To check for a BOM open the file in notepad and look at the encoding that is set.

    UTF-8 characters are just ASCII characters unless you have a BOM that specifies a foreign character set.

    Worst case is a character encoded UTF-8 that the BOM has been removed from by another system.  Specifying UTF-8BOM will not fix this.


    \_(ツ)_/

    Tuesday, February 11, 2020 12:45 PM
  • I tried. I get the same result ... 
    Wednesday, February 12, 2020 7:17 AM
  • I tried. I get the same result ... 

    What did you try?  You have to be explicit in tech forums.  We cannot guess what you are doing or see your screen.


    \_(ツ)_/


    • Edited by jrv Wednesday, February 12, 2020 11:17 AM
    Wednesday, February 12, 2020 11:17 AM