使用Get-WMIobject Process找到服务的路径并提取版本信息

时间:2017-01-13 14:45:45

标签: powershell powershell-remoting get-wmiobject

我需要验证在我们的系统上运行的服务的版本。所以我已经接近但似乎无法弄明白。我正在使用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"

1 个答案:

答案 0 :(得分: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"
}