【问题标题】:Using Get-WMIobject Process to locate the path of a service and pull the version information使用Get-WMIobject Process 定位服务路径并拉取版本信息
【发布时间】:2017-01-13 14:45:44
【问题描述】:

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

【问题讨论】:

    标签: powershell powershell-remoting get-wmiobject


    【解决方案1】:

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

    【讨论】:

    • 这种工作,但似乎它正在拉本地主机路径而不是远程系统。为了测试它,我设置了 $computer 变量并运行 (Get-WmiObject all the .ProductVersion 我得到一个错误。codeGet-ItemProperty : 找不到路径 'C:\Program Files\Zabbix Agent\zabbix_agentd .exe',因为它不存在。在 line:2 char:42 + Select -ExpandProperty Path | Get-ItemProperty).VersionInfo.ProductVe ...code 我登录了那台机器并且服务存在并且正在运行。
    • 您可以将其包装在Invoke-Command 中,以便在远程计算机上完成对VersionInfo 的查询。我已经编辑了我的答案来做到这一点。
    猜你喜欢
    • 1970-01-01
    • 2012-09-16
    • 2021-12-21
    • 2014-08-22
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多