How to check if a port is in use using powershell

Viewed 22243

Is there a way in powershell to check if a given port is in use or not?

3 Answers

Use Get-NetTCPConnection

Get-NetTCPConnection | where Localport -eq 5000 | select Localport,OwningProcess

Localport OwningProcess
--------- -------------
    5000          1684

If you are using PowerShell Core v6 and above use Test-Connection

>Test-Connection localhost -TcpPort 80
True

Following the other answers, once you run Get-NetTCPConnection | where Localport -eq 5000 | select Localport,OwningProcess you can check which process/application is using the port by running Get-Process

Get-Process -Id <OwningProcess>
Related