【问题标题】:WMI - get unlocalized OS nameWMI - 获取未本地化的操作系统名称
【发布时间】:2017-10-13 07:48:39
【问题描述】:

我需要从 WMI 检索操作系统名称。有没有办法在未本地化的情况下检索它? 目前,我正在通过美国区域设置,但检索到的操作系统名称仍在俄罗斯区域设置中。

我使用了以下内容:

(Get-WmiObject -Class Win32_OperatingSystem -Locale ms_409).Name

有什么想法吗?

【问题讨论】:

  • 为什么一定要来自WMI?

标签: windows powershell localization wmi get-wmiobject


【解决方案1】:

不幸的是,WMI 中没有包含操作系统名称的通用语言属性。 但是,通过这段小代码,您可以获得所需的信息:

$WMIOS = (Get-WmiObject -Class Win32_OperatingSystem)
$SytemType = [String]::Empty

$OS = [String]::Empty
switch ($WMIOS.ProductType)
{
    '1' 
    {
        switch ( $WMIOS.Version)
       {
        {$_ -like "6.0*"} {$OS = "Windows Vista";break}
        {$_ -like "6.1*"} {$OS = "Windows 7";break}
        {$_ -like "6.2*"} {$OS = "Windows 8";break}
        {$_ -like "6.3*"} {$OS = "Windows 8.1";break}
        {$_ -like "10*"} {$OS = "Windows 10";break}
        Default {Return}
        }
    }
    {$_ -in '2','3'} 
    {
        switch ( $WMIOS.Version)
        {
            {$_ -like "6.0*"} {$OS = "Windows Server 2008";break}
            {$_ -like "6.1*"} {$OS = "Windows Server 2008 R2";break}
            {$_ -like "6.2*"} {$OS = "Windows Server 2012";break}
            {$_ -like "6.3*"} {$OS = "Windows Server 2012 R2 ";break}
            {$_ -like "10*"} {$OS = "Windows Server 2016";break}
            Default {Return}
           }
        }
    }
}

$ProductSKU = [String]::Empty
switch ( $WMIOS.OperatingSystemSKU)
{
    '1' {$ProductSKU = "Ultimate";break}
    '2' {$ProductSKU = "Home Basic";break}
    '3' {$ProductSKU = "Home Premium";break}
    '4' {$ProductSKU = "Enterprise";break}
    '6' {$ProductSKU = "Professional";break}
    '7' {$ProductSKU = "Standard";break}
    '8' {$ProductSKU = "Datacenter";break}
    '9' {$ProductSKU = "Small Business";break}
    '10' {$ProductSKU = "Enterprise";break}
    '11' {$ProductSKU = "Starter";break}
    '12' {$ProductSKU = "Datacenter CORE";break}
    '13' {$ProductSKU = "Standard CORE";break}
    '14' {$ProductSKU = "Enterprise CORE";break}
    '17' {$ProductSKU = "WEB Server";break}
    '19' {$ProductSKU = "Home Server";break}
    '20' {$ProductSKU = "Storage Express Server";break}
    '21' {$ProductSKU = "Storage Standard Server";break}
    '22' {$ProductSKU = "Storage Workgroup Server";break}
    '23' {$ProductSKU = "Storage Enterprise Server";break}
    '24' {$ProductSKU = "Product Server For Small Business";break}
    '25' {$ProductSKU = "Product Small Business Server Premium";break}
    '27' {$ProductSKU = "Product Enterprise N";break}
    '28' {$ProductSKU = "Product Ultimate N";break}
    '29' {$ProductSKU = "Web Server CORE";break}
    '36' {$ProductSKU = "Standard Server V";break}
    '37' {$ProductSKU = "Datacenter Server V";break}
    '38' {$ProductSKU = "Enterprise Server Core V";break}
    '39' {$ProductSKU = "Datacenter Server Core V";break}
    '40' {$ProductSKU = "Standard Server Core V";break}
    '41' {$ProductSKU = "Enterprise Server Core V";break}
    '42' {$ProductSKU = "Hyper-V";break}
    '43' {$ProductSKU = "Storage Express Server Core";break}
    '44' {$ProductSKU = "Storage Standard Server Core";break}
    '45' {$ProductSKU = "Storage Workgroup Server Core";break}
    '46' {$ProductSKU = "Storage Enterprise Server Core";break}
    '50' {$ProductSKU = "SB Solution Server";break}
    '63' {$ProductSKU = "Small Business Server Premium Core";break}
    '64' {$ProductSKU = "Cluster Server V";break}
    '97' {$ProductSKU = "Product Core ARM";break}
    '101' {$ProductSKU = "Product Core";break}
    '103' {$ProductSKU = "Professional WMC";break}
    '104' {$ProductSKU = "Product Mobile Core";break}
    '123' {$ProductSKU = "Product IOTUAP";break}
    '143' {$ProductSKU = "Product Datacenter Nano Server";break}
    '144' {$ProductSKU = "Product Standard Nano Server";break}
    '147' {$ProductSKU = "Product Datacenter WS Server Core";break}
    '147' {$ProductSKU = "Product Standard WS Server Core";break}
    Default {$ProductSKU = "Undefined"}
}

Return ($OS + " " + $ProductSKU)

【讨论】:

  • IMO 硬编码产品名称列表不是一个好的解决方案(不是面向未来的)。
  • 嗨,这个列表在操作系统中是硬编码的。所以在我看来,它会很复杂,不会让它更有活力。另一种选择是使用 win32_OperatingSystem 对象的 Caption 属性,但它是依赖于语言的。
猜你喜欢
  • 2019-01-19
  • 2018-02-01
  • 1970-01-01
  • 2015-05-25
  • 1970-01-01
  • 1970-01-01
  • 2011-09-13
  • 1970-01-01
  • 2017-06-15
相关资源
最近更新 更多