question

AndyLester-2522 avatar image
0 Votes"
AndyLester-2522 asked MotoX80 answered

Get-Process and port filtering

I have this script to find all processes and ports on my machine that have the NetTCPConnection State set to "Listen" Get-NetTCPConnection -State Listen | Select-Object -Property LocalAddress, LocalPort, RemoteAddress, RemotePort, State,@{name='Process';expression={(Get-Process -Id $_.OwningProcess).Name}}, CreationTime | Format-Table -AutoSize How do I filter the output so I can only see a particular service, or set of services from the full list? im looking for something like: eg where servicename like "svhost* or where servicename like "s*" thanks

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MotoX80 avatar image
0 Votes"
MotoX80 answered
 Get-NetTCPConnection -State Listen | Select-Object -Property LocalAddress, LocalPort, RemoteAddress, RemotePort, State,@{name='Process';expression={(Get-Process -Id $_.OwningProcess).Name}}, CreationTime | where-object -property Process -match 'syst' |  Format-Table -AutoSize
 Get-NetTCPConnection -State Listen | Select-Object -Property LocalAddress, LocalPort, RemoteAddress, RemotePort, State,@{name='Process';expression={(Get-Process -Id $_.OwningProcess).Name}}, CreationTime | where-object {($_.process -match 'svchost') -or ($_.process -match 'spool')}|  Format-Table -AutoSize
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.