PowerShell: Get Open Ports

Need to check which ports are open and listening for incoming connections - for security auditing or troubleshooting a network service? This one-liner pulls it straight from the system.

Prerequisites:

  • Privileges: None
  • Module: Built-in, no import needed

Quick Command:

Get-NetTCPConnection -State Listen | Select-Object LocalAddress, LocalPort, State

Example Output:

LocalAddress  LocalPort  State
------------  ---------  -----
::                49664 Listen
127.0.0.1         49670 Listen
0.0.0.0             445 Listen
0.0.0.0             139 Listen
0.0.0.0             135 Listen
0.0.0.0           16992 Listen
0.0.0.0             623 Listen
📦
Want all of them at once?
Get every free one-liner from this blog in a single downloadable bundle organized by category, each with full comment-based help. No more copy-pasting one at a time.

How It Works:

  • Get-NetTCPConnection returns every TCP connection the system has, in any state - established connections to websites, closing connections, and ports listening for incoming traffic, all mixed together.
  • -State Listen filters down to only ports actively listening for incoming connections - these are the genuinely "open" ports, as opposed to outbound connections to remote servers (which show as Established).
  • LocalAddress of 0.0.0.0 or :: means the port is listening on all network interfaces; a specific IP (like 192.168.1.144) means it only accepts connections from that specific address.