Change the current culture of a Powershell session, v3.0+ specific -
i want change culture of accepted data , errors in current interactive powershell session. aware of question powershell : changing culture of current session , of question changing current culture on superuser. main problem doesn't work powershell 3.0 , 4.0.
ps c:\users\me\documents> [system.threading.thread]::currentthread.currentculture lcid name displayname ---- ---- ----------- 1049 ru-ru Русский (Россия) ps c:\users\me\documents> [system.threading.thread]::currentthread.currentculture=[system.globalization.cultureinfo]"en-us" ps c:\users\me\documents> [system.threading.thread]::currentthread.currentculture lcid name displayname ---- ---- ----------- 1049 ru-ru Русский (Россия)
ui culture not accept new settings. set-culture
in total not work, regardless of whether i'm using admin access or not - anyway, shouldn't affected this, effect single process. using-culture
msdn powershell blog, adapted community, works, partially, example, current culture of "ru-ru" able proper date "6/19/15 2:26:02 pm" string, in "en-us" culture via using-culture "en-us" {get-date -date "6/19/15 2:26:02 pm"}
, receiving error in language not possible: using-culture "en-us" {$null.test='1'}
results in error russian locale, if culture not changed.
this behavior tested on local win7 professional workstation powershell 4.0 installed, , windows server 2012 powershell 3.0 installed, required parse wrongly localized date strings. latter has ui culture of "en-us" , system locale "ru-ru".
so, changing powershell session's culture still possible ps3 , above, , if yes, how? (or bugs again, or change in ps3 not aware of?)
changing culture affects thread , applicable process. ps window launched under current locale , therefore thread has locale. typing "[system.threading.thread]::currentthread.currentculture" ps window launched under current system locale, show locale.
if run in ise should explain 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 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 want ps window new culture, you'll need launch using culture, not try , change afterwards.
Comments
Post a Comment