Powershell:获取计算机信息

Powershell:获取计算机信息

有人知道如何获取这样的操作系统版本吗:

操作系统版本:1607

使用 Get-WmiObject?根本找不到这个信息。

答案1

对原始问题的简单回答难道不是如下吗:

Get-ComputerInfo | select windowsversion

WindowsVersion -------------- 1903

答案2

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

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

答案3

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

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 "--------------------------------------------------------"
                    

答案4

Get-WmiObject 可以为您提供版本号和编号,例如

(Get-WmiObject Win32_OperatingSystem).Version

或者

(Get-WmiObject Win32_OperatingSystem).BuildNumber

如果您想要有关操作系统的更多一般信息,我建议您使用 Get-Item cmdlet,并搜索“ProductName”而不是上面提到的“relaseID”键。

(Get-Item "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('ProductName')

很酷的是,这些命令可以适用于 Windows 7 到 Windows 10 以及 Server 2012 到 2019。如果您需要获取有关工作站的信息或在混合环境中对工作站应用任务,它很有用。

相关内容