获取计算机操作系统版本

时间:2016-05-11 12:34:15

标签: powershell

此脚本可以正常运行以获取操作系统版本。我需要知道在结果中只能获得Microsoft Windows 10 Pro的人

$Computers = Get-Content C:\computerlist

Foreach($Computer in $Computers)
{ 


Get-WmiObject Win32_OperatingSystem -ComputerName $Computer -ErrorAction  SilentlyContinue | Select-Object CSName, Caption | sort CSName


}

2 个答案:

答案 0 :(得分:2)

我不确定我是否理解你,但我认为你需要Where-Object

$Computers = Get-Content C:\computerlist

Foreach($Computer in $Computers)
{ 
  Get-WmiObject Win32_OperatingSystem -ComputerName $Computer -ErrorAction  SilentlyContinue | Select-Object CSName, Caption | where Caption -eq "Microsoft Windows 10 Pro" | sort CSName
}

答案 1 :(得分:0)

如果您只想要Caption值,请使用Select-Object -ExpandProperty Caption

foreach($Computer in $Computers)
{
    Get-WmiObject Win32_OperatingSystem -ComputerName $Computer -ErrorAction  SilentlyContinue | Select-Object -ExpandProperty Caption
}