如何获得Windows版本?

deyfvvtc  于 2022-12-19  发布在  Windows
关注(0)|答案(4)|浏览(141)

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

  1. Windows版本有代码吗?
    1.如果没有代码,并且唯一的方法是Get-WmiObject -Class Win32_OperatingSystem | % Caption,我如何格式化它以在任何windows操作系统上选择版本?
    1.有没有别的办法?
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx
2cmtqfgy

2cmtqfgy1#

该信息编码在Win32_OperatingSystem类的OperatingSystemSKU属性中:

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

将上面的列表放入hashtable中,以便将整数值Map到描述:

$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属性。

w51jfk4q

w51jfk4q3#

只需用途:

Get-ComputerInfo | select WindowsProductName, OsOperatingSystemSKU, OsName | fl

# <output>
# WindowsProductName   : Windows 10 Home
# OsOperatingSystemSKU : WindowsHome
# OsName               : Microsoft Windows 10 Home

如果您需要其他项目,请从以下列表中查找:

# (Get-CimInstance Win32_OperatingSystem) | select *

Status                                    : OK
Name                                      : <rest is redacted>
FreePhysicalMemory                        :
FreeSpaceInPagingFiles                    :
FreeVirtualMemory                         :
Caption                                   :
Description                               :
InstallDate                               :
CreationClassName                         :
CSCreationClassName                       :
CSName                                    :
CurrentTimeZone                           :
Distributed                               :
LastBootUpTime                            :
LocalDateTime                             :
MaxNumberOfProcesses                      :
MaxProcessMemorySize                      :
NumberOfLicensedUsers                     :
NumberOfProcesses                         :
NumberOfUsers                             :
OSType                                    :
OtherTypeDescription                      :
SizeStoredInPagingFiles                   :
TotalSwapSpaceSize                        :
TotalVirtualMemorySize                    :
TotalVisibleMemorySize                    :
Version                                   :
BootDevice                                :
BuildNumber                               :
BuildType                                 :
CodeSet                                   :
CountryCode                               :
CSDVersion                                :
DataExecutionPrevention_32BitApplications :
DataExecutionPrevention_Available         :
DataExecutionPrevention_Drivers           :
DataExecutionPrevention_SupportPolicy     :
Debug                                     :
EncryptionLevel                           :
ForegroundApplicationBoost                :
LargeSystemCache                          :
Locale                                    :
Manufacturer                              :
MUILanguages                              :
OperatingSystemSKU                        :
Organization                              :
OSArchitecture                            :
OSLanguage                                :
OSProductSuite                            :
PAEEnabled                                :
PlusProductID                             :
PlusVersionNumber                         :
PortableOperatingSystem                   :
Primary                                   :
ProductType                               :
RegisteredUser                            :
SerialNumber                              :
ServicePackMajorVersion                   :
ServicePackMinorVersion                   :
SuiteMask                                 :
SystemDevice                              :
SystemDirectory                           :
SystemDrive                               :
WindowsDirectory                          :
PSComputerName                            :
CimClass                                  :
CimInstanceProperties                     :
CimSystemProperties                       :
t5zmwmid

t5zmwmid4#

我通常在Windows10上运行这样的程序,你也可以从ubr上看到你的每月更新。

# vercheck.ps1
$reg = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
$releaseid = $reg.releaseid
$ubr = $reg.ubr
$displayversion = $reg.displayversion

[pscustomobject]@{
  releaseid = $releaseid
  displayversion = $displayversion
  ubr = $ubr
}
releaseid displayversion  ubr
--------- --------------  ---
2009      21H2           2251

相关问题