Identifying ports in use on Windows via Powershell
Apr 8, 2020

Background

Occasionally you might find yourself struggling to launch an application or website that you’ve been building locally, due to a port conflict issue. If you’re unable to change the port on either of the applications, you then find yourself in the predicament of trying to figure out which application it is that is using said port, so you can see if its an app that isn’t essential and can therefore be closed allowing you to continue your original task.

In Powershell (or command prompt), you can get a list of ports that are currently in use by running

netstat -a

The output will look something like this:

Filter

We’re able to filter this list, if we run the following command

netstat -aon | findstr "4000"

The output returned will look like this:

Identifying the process the port belongs too

OK, that last column on the right (which has 22344 in the above screen-shot), tells use the PID (process ID) of whichever application is using the port.

Using the following command, we can filter by the PID we’ve just obtained

tasklist | findstr 22344

which will yield an output like the below

This tells me that its Docker that is using the port 4000.