Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Set the default en coding to UTF-8 in powershell. As seen in http://blogs.msdn.com/b/powershell/archive/2006/12/11/outputencoding-to-the-rescue.aspx
$OutputEncoding = New-Object -typename System.Text.UTF8Encoding
[Console]::OutputEncoding = New-Object -typename System.Text.UTF8Encoding
@Tiliavir

This comment has been minimized.

Copy link

@Tiliavir Tiliavir commented Sep 14, 2016

first line is irrelevant, right?

@Velocet

This comment has been minimized.

Copy link

@Velocet Velocet commented Sep 30, 2016

I prefer writing it this way:

[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8

Another way is to use chcp.com:

& "$env:windir\system32\chcp.com" 65001

@isalgueiro

This comment has been minimized.

Copy link

@isalgueiro isalgueiro commented Jul 17, 2017

@Tiliavir $OutputEncoding controlls how text is passed through pipes https://blogs.msdn.microsoft.com/powershell/2006/12/11/outputencoding-to-the-rescue/

@Memnarch

This comment has been minimized.

Copy link

@Memnarch Memnarch commented Apr 3, 2018

Just leaving this as an alternative if it is required to start a Powershell childprocess instantly as UTF8 (including pipes) without running an external script:
Powershell.exe -NoExit -Command "$OutputEncoding = [Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8"

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jun 13, 2018

Add $env:LC_ALL='C.UTF-8' to your $profile.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Mar 24, 2019

"$OutputEncoding = [Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8"
This works...

@brunorozendo

This comment has been minimized.

Copy link

@brunorozendo brunorozendo commented Mar 19, 2020

Add $env:LC_ALL='C.UTF-8' to your $profile.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.