Change the current culture of a Powershell session, v3.0+ specific

99封情书 提交于 2019-12-04 15:08:53

Changing culture only affects a the thread and is only applicable to that process. Your PS window is launched under the current locale and therefore the thread has that locale. Typing "[System.Threading.Thread]::CurrentThread.CurrentCulture" into a PS window launched under the current system locale, will always show that locale.

If you run this in ISE it should explain it little:

 function Set-Culture([System.Globalization.CultureInfo] $culture) {
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture }

Set-Culture en-US
[system.threading.thread]::currentthread.currentculture
Pause

Or, in a PS window:

function Set-Culture([System.Globalization.CultureInfo] $culture) { [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture ; [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture } ; Set-Culture en-US ; [system.threading.thread]::currentthread.currentculture

It works fine.

If you want a PS window with a new culture, you'll need launch it using that culture, not try and change it afterwards.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!