【发布时间】:2015-06-19 11:27:47
【问题描述】:
我想改变当前交互式 Powershell 会话中接受数据和错误的文化。我知道这个问题powershell : changing the culture of current session 和这个问题Changing current culture 关于超级用户。它不适用于 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 文化也不接受新设置。 Set-Culture 总共不起作用,无论我是否使用管理员访问权限 - 无论如何,它不应该受此影响,因为效果仅适用于单个进程。来自 MSDN Powershell 博客的 Using-Culture 由 SO 社区改编,但仅部分有效,例如,在当前的“ru-RU”文化下,我能够从“6/19/15 2:26: 02 PM" 字符串,通过Using-Culture "en-US" {get-date -date "6/19/15 2:26:02 PM"} 在“en-US”文化中,但不可能收到另一种语言的错误:比如Using-Culture "en-US" {$null.test='1'} 导致俄语语言环境出错,就好像文化没有改变.
此行为已在安装了 Powershell 4.0 的本地 Win7 Professional 工作站和安装了 Powershell 3.0 的 Windows Server 2012 上进行了测试,这是解析错误本地化的日期字符串所必需的。后者具有“en-US”的 UI 文化和系统区域设置“ru-RU”。
那么,PS3 及更高版本是否仍然可以改变 Powershell 会话的文化,如果可以,如何? (或者是再次出现错误,还是我不知道的 PS3 变化?)
【问题讨论】:
标签: powershell powershell-3.0 culture powershell-4.0