如何使用 Get-TCPConnection 并获取有关进程的更多信息?恰好是进程文件版本?

How can I use Get-TCPConnection and get more information about the processes? Precisely the Processes File Version?

cmdlet Get-TCPConnection 的输出不包括文件版本,出于学术目的,我需要该信息。

我试过很多纸条,他们就是不提供这个准确的信息。

假设 this 是您从中获取脚本的地方,我做了一些小的调整。我不会 post 整个脚本,所以我只会 post 我所做的更改。

第 130 行。在末尾添加了 FileVersion 属性。

$properties = 'ComputerName','Protocol','LocalAddress','LocalPort','RemoteAddress','RemotePort','State','ProcessName','PID', 'Fileversion'

第 144 行。在末尾添加了 FileVersion属性。

$processes = Get-Process -ComputerName $Computer -ErrorAction stop | select name, id, FileVersion

第 302 行。删除了 -ExpandProperty 并添加了 Fileversion

if($procName = $processes | Where {$_.id -eq $procId} | select name, FileVersion ){ }

现在是结局,第 362-373 行,调整了 PSObject 的创建方式以包含我们的新更改。

New-Object -TypeName PSObject -Property @{
                                ComputerName = $Computer
                                PID = $procId
                                ProcessName = $procName.Name
                                Protocol = $proto
                                LocalAddress = $localAddress
                                LocalPort = $localPort
                                RemoteAddress =$remoteAddress
                                RemotePort = $remotePort
                                State = $status
                                FileVersion = $procName.FileVersion
                            } | Select-Object -Property $properties