使用Get-WMIobject Process定位服务路径并拉取版本信息

Using Get-WMIobject Process to locate the path of a service and pull the version information

我需要在我们的系统上验证服务 运行 的版本。所以我已经接近但似乎无法弄清楚。我正在使用 Get-WmiObject 进程寻找 运行 服务的进程。然后拉回 "the" 服务的可执行文件的路径。然后检索所述可执行文件的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"

删除 ?/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"
}