Get-Process and port filtering

Andy Lester 1 Reputation point
2021-03-30T15:41:23.88+00:00

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
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,381 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 31,816 Reputation points
    2021-03-30T16:12:09.45+00:00
    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
    
    0 comments No comments