brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Get-NetTCPConnection -State Listen shows which ports your PC is listening on

Troubleshooting
~/tips/tip-windows-get-nettcpconnection-listen

Get-NetTCPConnection -State Listen

Lists every TCP port Windows is listening on, with the process ID that owns each one.

Every few months I wonder what on earth is listening on a port on a Windows machine. netstat can answer that, but PowerShell has a cmdlet that returns real objects, so you can filter and sort without squinting at columns.

Get-NetTCPConnection -State Listen

That lists the TCP sockets in the Listen state. The cmdlet takes -LocalPort and -OwningProcess as well, so you can narrow it down in the same command:

Get-NetTCPConnection -State Listen -LocalPort 443
Get-NetTCPConnection -OwningProcess 1234

The first one tells you whether something is listening on port 443. The second shows every connection that belongs to the process with ID 1234. Swap in a real process ID from Task Manager or Get-Process.

To see a compact view, select the columns you care about:

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

The OwningProcess value is a process ID. To turn it into a program name, look that ID up with Get-Process -Id. The docs don’t show that combination, but it is the usual way to do it.

A caveat: the cmdlet only covers TCP, so a UDP listener will not show up here. -State accepts other values too, such as Established and TimeWait, which is handy when you want to see who is currently connected instead.

Further reading: Get-NetTCPConnection documentation

More Troubleshooting tips modinfo -p usb_storage ps -o pid,lstart,etime,cmd -p 1234 sudo lsof -nP -p 1234 fc-match Helvetica wp plugin list --status=active --field=name > active-plugins.txt All Troubleshooting tips (21) All topics

Link