Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 使用Get-WMIobject进程定位服务的路径并提取版本信息_Powershell_Powershell Remoting_Get Wmiobject - Fatal编程技术网

Powershell 使用Get-WMIobject进程定位服务的路径并提取版本信息

Powershell 使用Get-WMIobject进程定位服务的路径并提取版本信息,powershell,powershell-remoting,get-wmiobject,Powershell,Powershell Remoting,Get Wmiobject,我需要验证在我们的系统上运行的服务的版本。所以我已经接近了,但似乎无法理解。我正在使用Get WmiObject进程查找正在运行的服务的进程。然后,回调作为“服务”的可执行文件的路径。然后检索所述可执行文件的FileVersion foreach ($Computer in $Computers ) { $zabbix = Get-WmiObject -Class Win32_Process -ComputerName $computer -Filter "name like '%zab

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

删除
/
Where对象
,因为您没有进行筛选

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"
}

删除
/
Where对象
,因为您没有进行筛选

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所有的都是.ProductVersion,我得到一个错误。
code
Get-ItemProperty:找不到路径“C:\Program Files\Zabbix-Agent\Zabbix_-agentd.exe”,因为它不存在。在第2行char:42+选择-ExpandProperty路径| Get-ItemProperty).VersionInfo.ProductVe…
code
我已登录到该计算机,该服务已存在并正在运行。您可以将其包装在
Invoke命令中,以便在远程计算机上完成对
VersionInfo
的查询。我已经编辑了我的答案,这样做是可行的,但它似乎是在拉本地主机路径,而不是远程系统。为了测试它,我设置$computer变量并运行(Get-WmiObject所有的都是.ProductVersion,我得到一个错误。
code
Get-ItemProperty:找不到路径“C:\Program Files\Zabbix-Agent\Zabbix_-agentd.exe”,因为它不存在。在第2行char:42+选择-ExpandProperty路径| Get-ItemProperty).VersionInfo.ProductVe…
code
我已登录到该计算机,该服务已存在并正在运行。您可以将其包装在
Invoke命令中,以便在远程计算机上完成对
VersionInfo
的查询。我已经编辑了我的答案。