PowerShell: Get-NetTCPConnection Usage | Generated by AI

Home PDF

The Get-NetTCPConnection cmdlet in PowerShell retrieves information about TCP connections on a Windows system. It’s part of the NetTCPIP module, available on Windows 8/Windows Server 2012 and later. Below is a concise guide on how to use it:

Basic Usage

Run Get-NetTCPConnection to list all active TCP connections:

Get-NetTCPConnection

This returns details like LocalAddress, LocalPort, RemoteAddress, RemotePort, State, and OwningProcess.

Common Parameters

Combining Filters

You can combine parameters for more specific results:

Get-NetTCPConnection -State Established -LocalPort 80

Display Specific Properties

Use Select-Object to show only desired properties:

Get-NetTCPConnection | Select-Object LocalAddress, LocalPort, RemoteAddress, RemotePort, State

Find Process Details

To identify the process behind a connection, combine with Get-Process:

Get-NetTCPConnection -LocalPort 80 | ForEach-Object { Get-Process -Id $_.OwningProcess }

Sort and Format Output

Sort results (e.g., by LocalPort) and format as a table:

Get-NetTCPConnection | Sort-Object LocalPort | Format-Table LocalAddress, LocalPort, RemoteAddress, RemotePort, State

Practical Examples

  1. List all listening connections:
    Get-NetTCPConnection -State Listening
    
  2. Find connections to a specific remote server:
    Get-NetTCPConnection -RemoteAddress "8.8.8.8"
    
  3. Check which process is using a specific port:
    $connection = Get-NetTCPConnection -LocalPort 8080
    Get-Process -Id $connection.OwningProcess
    

Notes

For more details, run:

Get-Help Get-NetTCPConnection -Full

If you need specific examples or have a particular use case, let me know!


Back 2025.05.28 Donate