[英]Convert CountryCode of Win32_OperatingSystem to the country string
We're trying to convert the CountryCode
in to a human readable String
. 我们正在尝试将
CountryCode
转换为人类可读的String
。
Code: 码:
$OS = Get-CimInstance -ClassName Win32_OperatingSystem
$OS | Select-Object CountryCode, OSLanguage,
@{N = 'OSDefaultLanguage'; E = {New-Object System.Globalization.CultureInfo([Int]$_.OSLanguage)}},
@{N = 'OSCountryCode'; E = {New-Object System.Globalization.CultureInfo([Int]$_.CountryCode)}}
In the example above the property OSCountryCode
is what we need. 在上面的示例中,属性
OSCountryCode
是我们需要的。 But it returns the value ar
which is Argentina
but it should return United States
according to the documentation for value 1
. 但它返回值为
ar
的Argentina
但它应该根据值1
的文档返回United States
。
How can value 1
be correctly converted to US
or something similar? 如何将价值
1
正确转换为US
或类似的东西?
$OS = Get-CimInstance -ClassName Win32_OperatingSystem
$Culture = [System.Globalization.CultureInfo]::GetCultures("SpecificCultures") | Where {$_.LCID -eq $OS.OSLanguage}
$RegionInfo = New-Object System.Globalization.RegionInfo $Culture.Name
$OS | Select-Object CountryCode, OSLanguage,
@{N = 'OSDefaultLanguage'; E = {New-Object System.Globalization.CultureInfo([Int]$_.OSLanguage)}},
@{N = 'OSCountryCode'; E = {$RegionInfo.TwoLetterISORegionName}},
@{N = 'OSCountryName'; E = {$RegionInfo.DisplayName}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.