开发者

How to check if a port is in use using powershell

开发者 https://www.devze.com 2023-03-25 19:17 出处:网络
Is there a way in pow开发者_运维技巧ershell to check if a given port is in use or not? Use Get-NetTCPConnection

Is there a way in pow开发者_运维技巧ershell to check if a given port is in use or not?


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>


You could just roll it into one:

Get-NetTCPConnection | where Localport -eq 5000| Select-Object Localport,@{'Name' = 'ProcessName';'Expression'={(Get-Process -Id $_.OwningProcess).Name}}

0

精彩评论

暂无评论...
验证码 换一张
取 消