2017-05-26 97 views
1

如果我在本地做,我得到的所有信息:获取过程的产品版本的远程计算机

get-process | select-object name,fileversion,company 

但是,如果我做一个远程计算机上我只得到进程的名称和所有其他字段空白。有谁知道为什么或如何获得相同的信息。我正在使用域管理员凭据,因此我应该可以访问该信息。

get-process -computername xcomp123 | select-object name,fileversion,company 
+1

我看到同样的事情。你可以用'Invoke-Command - 计算机名xcomp123 -ScriptBlock {Get-Process}获得你想要的信息。选择对象名称,文件版本,公司。 (假设你已经配置PS Remoting)。看看为什么它不起作用 - 它调用.Net框架为本地进程调用'[system.diagnostics.process] :: GetProcess()'和'[system.diagnostics.process] :: GetProcess('xcomp123' )'用于远程进程,所以它不在PowerShell的手中,为什么远程不能使用版本。此外,如果您在本地'gwmi win32_process',则不会返回版本信息。 – TessellatingHeckler

+0

您可以从executablepath属性中获取该信息。因为我现在没有时间,所以我会提供更新。 – restless1987

回答

0

你可以试试这个解决方案:

$Computername = 'Remotehost' 

$Session = New-CimSession -ComputerName $Computername 

$process = Get-CimInstance -ClassName Win32_Process -CimSession $Session 

$col = New-Object System.Collections.ArrayList 

foreach ($n in $process){ 

    $exePath = $null 
    $ExeInfo = $null 

    $exePath = $n.ExecutablePath -Replace '\\','\\' 

    $ExeInfo = Get-CimInstance -ClassName Cim_DataFile -Filter "Name = '$exePath'" -ErrorAction SilentlyContinue 

    [void]$col.add([PSCustomObject]@{ 
     Name = $n.name 
     FileVersion = $ExeInfo.Version 
     Company = $ExeInfo.Manufacturer 
     PSComputername = $n.PSComputername 
    }) 
} 
Remove-Cimsession $session 
$col 

更新:

我减少了代码来检查只有一个进程。我声明与客户端计算机上的进程具有相同名称的引用文件。你可能会根据你的需要改变它。

您可以在$computername指定多台计算机,因此您不必一遍又一遍地运行代码。

#region Reference file 

$RefFile = Get-item "\\x123\c$\program files\prog\winagent\file.exe" 

#endregion 

#region remote file 

[string[]]$Computername = 'Remotehost1', 'Remotehost2' 
$Processname = $RefFile.Name 

foreach ($n in $Computername) { 
    $Session = New-CimSession -ComputerName $n 
    $process = Get-CimInstance -ClassName Win32_Process -CimSession $Session -Filter "name = '$Processname'" 
    $exePath = $process.ExecutablePath -Replace '\\', '\\' 
    $ExeInfo = Get-CimInstance -ClassName Cim_DataFile -Filter "Name = '$exePath'" -ErrorAction SilentlyContinue 
    [PSCustomObject]@{ 
      Name   = $Processname 
      FileVersion = $ExeInfo.Version 
      Company  = $ExeInfo.Manufacturer 
      PSComputername = $n 
     } 
    Remove-Cimsession $session 
} 

#endregion 
+0

我是要将内存中的进程版本与exe的文件版本进行比较,以查看它们是否相同。我们有一台服务器产品将代理发送到受监控的服务器。当我们升级主机服务器时,我们要确保远程进程是最新的。这是我写的: $ a = invokecommand -computername x123 -scriptblock {get- process} | where-object -filterscript {$ _。name-like“123”} | select- object fileversion $ path ='\\ x123 \ c $ \ program files \ prog \ winagent \ file.exe' $ b =(dir $ path).versioninfo compare-object $ a $ b – user445408

相关问题