PowerShell Genie

Get-NetTCPConnection

Use Get-NetTCPConnection to list TCP connections and listening ports with the owning process id.

Command 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — PowerShell module reference

Syntax

1PS> Get-NetTCPConnection [[-LocalAddress] <string[]>] [-LocalPort <UInt16[]>] [-RemoteAddress <String[]>] [-RemotePort <UInt16[]>] [-State <State[]>] [-OwningProcess <UInt32[]>] [-CimSession <CimSession[]>] [<CommonParameters>]
See the command anatomy

Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

Get-NetTCPConnection [[-LocalAddress] <string[]>] [-LocalPort <UInt16[]>] [-RemoteAddress <String[]>] [-RemotePort <UInt16[]>] [-State <State[]>] [-OwningProcess <UInt32[]>] [-CimSession <CimSession[]>] [<CommonParameters>]
  1. Stage 1Get-NetTCPConnection-LocalAddress -LocalPort -RemoteAddress -RemotePort -State -OwningProcess -CimSession

    Try it

    Windows PowerShell

    PowerShell example · browser support is limited.

    Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.

    Interactive simulation · fictional data

    Examples

    Get-NetTCPConnection -State Listen

    1PS> Get-NetTCPConnection -State Listen | Select-Object LocalAddress, LocalPort, OwningProcess
    Show reference output

    Sample output · fictional data, shaped like the real thing

    LocalAddress  LocalPort  OwningProcess
    ------------  ---------  -------------
    10.20.30.41   51544      9184
    10.20.30.41   51612      6620

    Get-NetTCPConnection -LocalPort 443

    1PS> Get-NetTCPConnection -LocalPort 443 | ForEach-Object { Get-Process -Id $_.OwningProcess }
    Show reference output

    Sample output · fictional data, shaped like the real thing

    LocalAddress  LocalPort  RemoteAddress   RemotePort  State        OwningProcess
    ------------  ---------  --------------  ----------  -----------  -------------
    10.20.30.41   51544      13.107.42.14    443         Established  9184
    10.20.30.41   51612      20.190.151.132  443         Established  6620

    Get-NetTCPConnection -State Established

    1PS> Get-NetTCPConnection -State Established | Group-Object OwningProcess -NoElement
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Count  Name
    -----  ----
    2      SampleA
    1      SampleB

    Parameters

    Parameter definitions:

    • -LocalAddress
    • -LocalPort
    • -RemoteAddress
    • -RemotePort
    • -State
    • -OwningProcess
    • -CimSession

    PowerShell module reference on Microsoft Learn

    Practical use and troubleshooting

    Practical scenario: Use Get-NetTCPConnection when you need to list TCP connections and listening ports with the owning process id. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.

    Common error and fix: A missing listener can mean the application is stopped or bound to another address. Inspect LocalAddress and LocalPort and check the owning process rather than changing the firewall first. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.

    See also: Test-NetConnection. Get-NetTCPConnection reads local TCP state; Test-NetConnection can test a remote TCP endpoint. A local Established connection is different from testing a new connection to a service. Read the linked command before substituting it; similar names do not imply identical inputs or output.

    Get-NetTCPConnection reference on Microsoft Learn

    Recap

    Get-NetTCPConnection Use Get-NetTCPConnection to list TCP connections and listening ports with the owning process id.

    Next: Get-ADGroupMember
    Genie guideGet-NetTCPConnection

    Use Get-NetTCPConnection to list TCP connections and listening ports with the owning process id. The console below is pre-loaded — run it, then change a value and run it again.