0

I need to verify the version of a service running on our systems. So I have got close but cannot seem to figure it out. I am using a Get-WmiObject process looking for the process of the service that is running. Then pull back the path of that executable that is "the" service. Then retrieve the FileVersion of said executable file.

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"
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Tram
  • 55
  • 2
  • 9

1 Answers1

2

Drop the ?/ Where-Object because you aren't filtering.

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"
}
BenH
  • 9,766
  • 1
  • 22
  • 35
  • That kind of worked but it seems like it is pulling the local host path rather than the remote system. To test it, I set the $computer variable and run the (Get-WmiObject all the was to .ProductVersion and I get an error. `code`Get-ItemProperty : Cannot find path 'C:\Program Files\Zabbix Agent\zabbix_agentd.exe' because it does not exist. At line:2 char:42 + Select -ExpandProperty Path | Get-ItemProperty).VersionInfo.ProductVe ...`code` I logged on that machine and the service is present and running. – Tram Jan 13 '17 at 17:47
  • You can wrap it in an `Invoke-Command` so that the querying of `VersionInfo` is done on the remote computer. I've edited my answer to do that. – BenH Jan 13 '17 at 18:04