PowerShell Genie

Find established endpoints

Script 1 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Group established TCP connections by remote address, then sort by count to find the endpoints with the most concurrent connections.

The script

1PS> Get-NetTCPConnection -State Established | Group-Object RemoteAddress | Sort-Object Count -Descending | Select-Object Name,Count

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 Name Count
    2 ---- -----
    3 20.40.60.80 12
    4 52.96.12.34 7
    Inspect this example’s structure

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

    Get-NetTCPConnection -State Established | Group-Object RemoteAddress | Sort-Object Count -Descending | Select-Object Name,Count
    1. Stage 1Get-NetTCPConnection-State
    2. Stage 2Group-ObjectPositional values or no named parameters
    3. Stage 3Sort-Object-Descending
    4. Stage 4Select-ObjectPositional values or no named parameters

      How it works

      Established connections are grouped by RemoteAddress, Sort-Object ranks the buckets by size, and the projection reports each address as Name alongside the number of concurrent connections to it.

      Adapting it

      Drop internal ranges before grouping with a Where-Object testing RemoteAddress against your own prefixes, which leaves only genuinely external destinations in the summary.

      If the result is unexpected

      The established-connection report misses short-lived endpoints.

      Connection tables are snapshots and ownership can change before a second process query.

      1. Collect connection and process identifiers close together and keep unresolved owners in the output.

      Validate the result

      Rows retain endpoint details even when a process exits before name resolution.

      Keep the check reliable

      Use repeated observations for transient traffic and avoid equating a snapshot with complete history.

      Primary documentation

      PowerShell objects and pipelines documentation

      Continue
      Genie guideFind established endpoints

      Group established TCP connections by remote address, then sort by count to find the endpoints with the most concurrent connections.