如何获得Windows版本? [英] How to get Windows edition?

查看:63
本文介绍了如何获得Windows版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 PowerShell 中创建一个脚本来验证操作系统版本(专业版、企业版、家庭版等).我找到了很多关于如何使用 ID 号验证操作系统版本(Vista、7、8、8.1 等)的信息,但我找不到有关版本代码的任何信息.我的问题是:

I need to create a script in PowerShell that verifies the OS edition (Pro, Enterprise, Home, etc.). I have found many information about how to verify with an ID number the OS version (Vista, 7, 8, 8.1, etc.), but I can't find anything about the editions codes. My questions are:

  1. 是否有适用于 Windows 版本的代码?
  2. 如果没有代码,唯一的办法就是Get-WmiObject -Class Win32_OperatingSystem |% Caption,如何格式化它以在任何 Windows 操作系统上选择版本?
  3. 还有其他方法可以做到这一点吗?
  1. Are there codes for Windows editions?
  2. If there are no codes, and the only way is Get-WmiObject -Class Win32_OperatingSystem | % Caption, how can I format this to select the edition on any windows operating system?
  3. Are there other ways to do this?

https://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx

推荐答案

该信息编码在 Win32_OperatingSystem 类:

That information is encoded in the OperatingSystemSKU property of the Win32_OperatingSystem class:

Value  Meaning
-----  -------
    0  Undefined
    1  Ultimate Edition
    2  Home Basic Edition
    3  Home Premium Edition
    4  Enterprise Edition
    5  Home Basic N Edition
    6  Business Edition
    7  Standard Server Edition
    8  Datacenter Server Edition
    9  Small Business Server Edition
   10  Enterprise Server Edition
   11  Starter Edition
   12  Datacenter Server Core Edition
   13  Standard Server Core Edition
   14  Enterprise Server Core Edition
   15  Enterprise Server Edition for Itanium-Based Systems
   16  Business N Edition
   17  Web Server Edition
   18  Cluster Server Edition
   19  Home Server Edition
   20  Storage Express Server Edition
   21  Storage Standard Server Edition
   22  Storage Workgroup Server Edition
   23  Storage Enterprise Server Edition
   24  Server For Small Business Edition
   25  Small Business Server Premium Edition
   29  Web Server, Server Core
   39  Datacenter Edition without Hyper-V, Server Core
   40  Standard Edition without Hyper-V, Server Core
   41  Enterprise Edition without Hyper-V, Server Core
   42  Hyper-V Server

将上面的列表放在哈希表中,用于映射整数对描述的价值:

Put the above list in a hashtable for mapping the integer value to the description:

$editions = @{
  0  = 'Undefined'
  1  = 'Ultimate Edition'
  2  = 'Home Basic Edition'
  ...
  41 = 'Enterprise Edition without Hyper-V, Server Core'
  42 = 'Hyper-V Server'
}

$sku = (Get-WmiObject Win32_OperatingSystem).OperatingSystemSKU

'Edition is {0}.' -f $editions[$sku]

但是请注意,OperatingSystemSKU 在 Server 2003 及更早版本上不可用.在这些系统上,您必须检查 Caption 和/或 OSProductSuite 属性.

Note, however, that OperatingSystemSKU is not available on Server 2003 and earlier. On those systems you'll have to check the Caption and/or OSProductSuite property.

这篇关于如何获得Windows版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆