IT Toolbox

List listening ports and Windows connections

View my favorites
PowerShell Low risk Administrator required

List listening ports and Windows connections

Shows the connections to TCP and links each PID to the corresponding process.

Command / script
Get-NetTCPConnection |
    Sort-Object State, LocalPort |
    ForEach-Object {
        $Process = Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue
        [PSCustomObject]@{
            Etat          = $_.State
            AdresseLocale = $_.LocalAddress
            PortLocal     = $_.LocalPort
            AdresseDistante = $_.RemoteAddress
            PortDistant   = $_.RemotePort
            PID           = $_.OwningProcess
            Processus     = $Process.ProcessName
        }
    } | Format-Table -AutoSize

When should you use it?

Useful for identifying which program is listening on a port or maintaining a remote connection.

What the script does

  • Get-NetTCPConnection retrieves TCP connections.
  • The PID is then resolved to a process name.

Precautions

  • A remote connection is not automatically malicious; verify the process and its context.

Rollback

Read-only operation.

♡ 0