get-nettcpconnection | select local*,remote*,state,@{Name='Process';Expression={(Get-Process -Id $_.OwningProcess).ProcessName }} 

is listing the all process, I need to filter by process name.

3

1 Answer

if I understood the question correctly, you want to have only certain processes returned. you can do that with a where filter.

add the processes you want to have returned in $searchfor

$searchfor = @("wininit","TeamViewer") get-nettcpconnection | select local*,remote*,state,@{Name='Process';Expression={(Get-Process -Id $_.OwningProcess).ProcessName }} | where { $_.Process -in $searchfor } 

you could also do it like this, which is probably a bit faster, since you run get-nettcpconnection only for the processes you're interested in:

$searchfor = @("wininit","TeamViewer") Get-Process $searchfor | % { $Proc = $_ Get-nettcpconnection -OwningProcess $_.ID | select local*,remote*,state,@{Name='Process';Expression={$Proc.ProcessName}} } 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy