如何通过带有WMI的Powershell获得OS版本?


5

有谁知道如何获得这样的操作系统版本:

作业系统版本:1607

使用Get-WmiObject吗?根本找不到此Informatin。


您使用Powershell的原因是什么?
marijnr

我必须在台式机信息软件中实现此信息,而唯一的方法是使用.ini文件和WMI查询
j.walt,2018年

1
尽管如此,powershell标签仍然不清楚:(Get-Item "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('ReleaseID')
LotPings

你试过了(Get-WmiObject Win32_OperatingSystem).Version吗?
桑迪普

@Sandeep版本将为您提供Microsoft用来标识其Windows版本的ID(版本6.1用于Windows 7,版本6.2用于Windows 10,...)
marijnr

Answers:


2

操作系统版本存储在注册表项中:HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ ReleaseId。通常,您可以使用WMI读取这些键。

LotPings在评论中提供了正确的查询:(Get-Item "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('ReleaseID')


1

它不是通过WMI进行的,但是Jeff Mercado的 回答可能是对任何帮助的回应

由于您可以访问.NET库,因此可以访问该类的OSVersion属性System.Environment以获取此信息。对于版本号,有Version属性。

例如,

PS C:\> [System.Environment]::OSVersion.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
6      1      7601   65536

Windows版本的详细信息可以在这里找到。


0

这是我编写的用于查找计算机信息的小脚本:

Powershell:获取计算机信息

$Computer = "localhost"
$Manufacturer = Get-WmiObject -ComputerName $Computer -class win32_computersystem | select -ExpandProperty Manufacturer
$Model = Get-WmiObject -class win32_computersystem -ComputerName $Computer | select -ExpandProperty model
$Serial = Get-WmiObject -class win32_bios -ComputerName $Computer | select -ExpandProperty SerialNumber
$wmi_os = Get-WmiObject -class Win32_OperatingSystem -ComputerName $Computer | select CSName,Caption,Version,OSArchitecture,LastBootUptime
switch($wmi_os.Version){
'10.0.10240'{$wmi_build="1507"}
'10.0.10586'{$wmi_build="1511"}
'10.0.14393'{$wmi_build="1607"}
'10.0.15063'{$wmi_build="1703"}
'10.0.16299'{$wmi_build="1709"}
'10.0.17134'{$wmi_build="1803"}
'10.0.17686'{$wmi_build="1809"}
}
$wmi_cpu = Get-WmiObject -class Win32_Processor -ComputerName $Computer | select -ExpandProperty DataWidth
$wmi_memory = Get-WmiObject -class cim_physicalmemory -ComputerName $Computer | select Capacity | %{($_.Capacity / 1024kb)}
$DNName = Get-ADComputer -Filter "Name -like '$Computer'" | select -ExpandProperty DistinguishedName
$Boot=[System.DateTime]::ParseExact($($wmi_os.LastBootUpTime).Split(".")[0],'yyyyMMddHHmmss',$null)
[TimeSpan]$uptime = New-TimeSpan $Boot $(get-date)
Write-Host "------Computer Info for $Computer------------------`r"
Write-Host "Hostname from WMI`: $($wmi_os.CSName)"
Write-Host "$DNName"
Write-Host "$Manufacturer $Model SN`:$Serial"
Write-Host "$($wmi_os.Caption) $wmi_build $($wmi_os.OSArchitecture) $($wmi_os.Version)"
Write-Host "CPU Architecture: $wmi_cpu"
Write-Host "Memory: $wmi_memory"
Write-Host "Uptime`: $($uptime.days) Days $($uptime.hours) Hours $($uptime.minutes) Minutes $($uptime.seconds) Seconds"
Write-Host "--------------------------------------------------------"

0

在TechNet Gallary中找到了这个很酷的脚本:Get-WindowsVersion

外观如下:

[19JUN] :>Get-WindowsVersion -ComputerName ktpc

ComputerName Productname           WindowsVersion WindowsBuild   ProductID               InstallTime
------------ -----------           -------------- ------------   ---------               -----------
KTPC         Windows 10 Enterprise 1803           10.0.17134.112 00329-10280-00000-AA451 5/22/2018 8:10:15 AM

它使用与其他建议的相同的“ RealseID”来获取此值。但是,这是很不错的努力,可以立即使用。


0

它没有使用Get-WmiObject,但请检查以下内容:

Get-ComputerInfo | 选择对象@ {Name ='Operating System'; Expression = {$ 。OsName}},@ {Name ='Version'; Expression = {$ .WindowsVersion}},@ {Name ='Build'; Expression = {$ .OsBuildNumber}},@ {Name ='Architecture'; Expression = {$ .OsArchitecture}},@ {Name ='System Root'; Expression = {$ .WindowsSystemRoot}},@ {Name ='Language'; Expression = {$ .OsLanguage}},@ {Name ='Boot State'; Expression = {$ _。CsBootupState}} | 格式表

要么

Get-ItemProperty'HKLM:SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion'| 选择对象ProductName,ReleaseID,CurrentBuild,SystemRoot

要么

只需采用我的程序并运行它即可。我已经在开发新版本,希望很快发布,因为新版本使用了更多的PowerShell和更少的WMIC命令。

https://sourceforge.net/projects/signature-by-mafii/files/

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.