Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

How to change locale of error messages of PowerShell interpreter

Problem

You can set locale of the current thread in PowerShell like below:

[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]("en-US")

But error messages of PowerShell interpreter shows in current locale.

PS > [System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]("en-US")
PS > x
x : 用語 'x' は、コマンドレット、関数、スクリプト ファイル、または操作可能なプログラムの名前として認識されません。名前
が正しく記述されていることを確認し、パスが含まれている場合はそのパスが正しいことを確認してから、再試行してください。
発生場所 行:1 文字:1
+ x
+ ~
    + CategoryInfo          : ObjectNotFound: (x:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Solution

You have to change current codepage and run another PowerShell process to show error messages in the specified locale.

PS > chcp 65001
Active code page: 65001
PS > powershell.exe
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS > x
x : The term 'x' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spell
ing of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ x
+ ~
    + CategoryInfo          : ObjectNotFound: (x:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException