简体   繁体   English

将Win32_OperatingSystem的CountryCode转换为国家/地区字符串

[英]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 . 但它返回值为arArgentina但它应该根据值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.

相关问题 CIM,Win32_OperatingSystem和Win32ShutdownTracker - CIM, Win32_OperatingSystem, and Win32ShutdownTracker 正则表达式从字符串(gwmi Win32_OperatingSystem).Name中提取数字 - Regex to extract number from string (gwmi Win32_OperatingSystem).Name Powershell GWMI win32_operatingsystem 修剪输出 - Powershell GWMI win32_operatingsystem trim output Get-CimInstance -ClassName Win32_bios, Win32_operatingsystem,? - Get-CimInstance -ClassName Win32_bios, Win32_operatingsystem,? PowerShell-Win32_OperatingSystem中的Select-Object显示异常 - PowerShell - Select-Object from Win32_OperatingSystem displays rather oddly cordova 安装错误 - 命令失败:powershell (Get-CimInstance -ClassName Win32_OperatingSystem).caption 术语“Get-CimInstance”不是重新 - cordova installation error -Command failed: powershell (Get-CimInstance -ClassName Win32_OperatingSystem).caption The term 'Get-CimInstance' is not re Powershell Win32_OperatingSystem选择标题与操作系统版本“ Microsoft Windows Server 2008 R2 Enterprise”进行比较导致错误的结果 - Powershell Win32_OperatingSystem select Caption compare with OS Version 'Microsoft Windows Server 2008 R2 Enterprise' resulting wrong result 将Get-WmiObject win32_diskdrive转换为Powershell 4中的阵列 - Convert Get-WmiObject win32_diskdrive to array in Powershell 4 如何将值从Get-WMIObject Win32_Printer中的值转换为ToUpper - How to convert values to ToUpper from values in Get-WMIObject Win32_Printer Win32_Service丢失 - Win32_Service is missing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM