COMMAND

Get-NetTCPConnectionList TCP connections as objects

Get-NetTCPConnection lists the machine's TCP connections and listening ports as PowerShell objects, so you can filter by state, port or process. It is the structured successor to netstat -ano, and joining it with Get-Process names the program that owns each port.

BlackhawkHub Editorial · Updated

Purpose

Get-NetTCPConnection gives you the same information as netstat but as objects, so filtering and sorting are trivial and you can join to process data without parsing text.

List listeners

powershell
Get-NetTCPConnection -State Listen | Sort-Object LocalPort |
  Select-Object LocalAddress, LocalPort, OwningProcess

Find the process owning a port

powershell
Get-Process -Id (Get-NetTCPConnection -LocalPort 8080 -State Listen).OwningProcess

This is the PowerShell equivalent of the netstat -ano plus tasklist two-step, in one line. See port 8080 for what commonly listens there.

Filter by state or remote host

powershell
Get-NetTCPConnection -State Established |
  Group-Object OwningProcess |
  Sort-Object Count -Descending
Get-NetTCPConnection -RemoteAddress 93.184.215.14

Grouping by OwningProcess shows which program has the most open connections, useful when a process is exhausting ephemeral ports.

Add the process name to every row

powershell
Get-NetTCPConnection -State Listen | ForEach-Object {
  [pscustomobject]@{
    Port = $_.LocalPort
    PID  = $_.OwningProcess
    Name = (Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue).ProcessName
  }
} | Sort-Object Port

States

Same as netstat: Listen, Established, TimeWait, CloseWait, SynSent and others. Filter with -State.

Common mistakes

  • Expecting UDP. Use Get-NetUDPEndpoint for UDP; see TCP vs UDP.
  • Not handling exited processes. A connection in TIME_WAIT may have no live process; use -ErrorAction SilentlyContinue on Get-Process.
  • Running elevated unnecessarily. Listing works without elevation; only some process details need it.

Frequently asked questions

How do I find which process owns a port in PowerShell?

Get-NetTCPConnection -LocalPort 8080 | Select-Object -ExpandProperty OwningProcess gives the PID; pipe it to Get-Process -Id for the name. One line: Get-Process -Id (Get-NetTCPConnection -LocalPort 8080).OwningProcess.

Does it show UDP?

No. Use Get-NetUDPEndpoint for UDP listeners. UDP has no connection state, so the output is just local endpoints and owning processes.

Sources