Erik Bitemo非常好!我当时想为路径添加变量,但我意识到尽管没有定义,但您已经知道了。所以我重用的代码是:
$nets = netstat -ano |select-string LISTENING;
foreach ($n in $nets)
{
# make split easier PLUS make it a string instead of a match object
$p = $n -replace ' +',' ';
# make it an array
$nar = $p.Split(' ')
# pick last item...
$pname = $(Get-Process -id $nar[-1]).ProcessName
$ppath = $(Get-Process -id $nar[-1]).Path;
# print the modified line with processname instead of PID
$n -replace "$($nar[-1])","$($ppath) $($pname)" | where {$pname -like "*GMSVP*"}
}
我试图找到一个应用程序的流程和服务,在该应用程序中我使用了一些不同的2衬板。
Get-Service | select status,name,displayname,servicename | where {($_.DisplayName -like "myserv*") -or ($_.servicename -like "post*")} | ft -auto
Get-Process | select id, processname,cpu,path,description | where {$_.path -like "*myserv*"} | ft -auto