Is there a way in powershell to check if a given port is in use or not?
Is there a way in powershell to check if a given port is in use or not?
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>