During my tinkering with PS 5.1 related to the objective of question Fully change language for the current PowerShell session I observed a "strange" behavior:
> [system.threading.thread]::currentthread.currentculture ; [system.threading.thread]::currentthread.currentuiculture ;
LCID Name DisplayName
---- ---- -----------
1033 en-US English (United States)
1033 en-US English (United States)
> function Set-CultureWin([System.Globalization.CultureInfo] $culture) { [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture ; [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture } ; Set-CultureWin es-ES ; [system.threading.thread]::currentthread.currentculture ; [system.threading.thread]::currentthread.currentuiculture ;
LCID Name DisplayName
---- ---- -----------
3082 es-ES Español (España)
3082 es-ES Español (España)
> [system.threading.thread]::currentthread.currentculture ; [system.threading.thread]::currentthread.currentuiculture ;
LCID Name DisplayName
---- ---- -----------
1033 en-US English (United States)
1033 en-US English (United States)
(the function above was obtained from here).
Replacing [system.threading.thread]::currentthread.
with [cultureinfo]::
everywhere produced exactly the same results.
What I found strange is:
I conclude that the boundary of a "thread" (the currentthread) appears to be the execution command line.
Nevertheless, here it is quoted as "a session-scoped (non-persistent) solution" (in response to its OP Temporarily change powershell language to English?). That answer even posted a wrapper function to limit the scope of the change to the executing command.
This information apparently opposes this, which states "[Threading.Thread]::CurrentThread.CurrentUICulture
only affects to current one-liner" (coinciding with my conclusion).I can obtain an immediate change of
Culture
for just that one "thread", even ifSet-Culture
only takes effect after launching a new session.
I might conclude that's how it works.
How can these two points be rationalized? (I would welcome authoritative documentation).