0

我需要验证我们系统上运行的服务的版本。所以我已经接近但似乎无法弄清楚。我正在使用一个Get-WmiObject进程来查找正在运行的服务的进程。然后拉回作为“该”服务的可执行文件的路径。然后检索FileVersion所述可执行文件的。

foreach ($Computer in $Computers ) {
    $zabbix = Get-WmiObject -Class Win32_Process -ComputerName $computer -Filter "name like '%zabbix%'" |
              Select -ExpandProperty Path |
              Get-ItemProperty |
              Select-Object -Property VersionInfo |
              ? {$_.ProductVersion}
}
Write-Host "$zabbix - $Computer"
4

1 回答 1

2

删除?/Where-Object因为您没有过滤。

ForEach ($Computer in $Computers ){
    $zabbix = Invoke-Command -ComputerName $Computer -ScriptBlock {
        (Get-WmiObject -Class Win32_Process -Filter "name like '%zabbix%'" |
        Select -ExpandProperty Path | Get-ItemProperty).VersionInfo.ProductVersion
    }
    Write-Host "$zabbix - $Computer"
}
于 2017-01-13T14:55:04.050 回答