Get the name of the process using a particular port

Hi,

Can someone help me to write a powershell function to retrieve the process-name of the process which is using a particular port.

The port number will be provided as input to the powershell function.

I tried using netstat -ano | select-string $Port 

But here I have to again depend on the cmdlet "Get-Process -Id XXXX | Format-Table ProcessName" whatever you got the PID in the previous cmdlet.

Can I get it using a single powershell function since Piping get-process and netstat -ano is not possible here. 

Please help!

Thanks in advance,

Aravind

September 3rd, 2015 4:47am

Hello,

I don't think that's possible natively. But you can find a function in this article to create a "Get-NetworkStatistics".

http://blogs.microsoft.co.il/scriptfanatic/2011/02/10/how-to-find-running-processes-and-their-port-number/

Example:

Free Windows Admin Tool Kit Click here and download it now
September 3rd, 2015 5:46am

Hi,

You can try this one:

function Port([string]$port=(Read-Host"Port number: ") )

{

$result =(netstat -ano | Select-String $port | select  @{l='id';expression={$_.Pattern}} | Get-Process).ProcessName

Write-Host $result

}

Hope it helps

 


  • Edited by VBosh 21 hours 17 minutes ago
September 3rd, 2015 5:54am

Hi,

You can try this one:

function Port([string]$port=(Read-Host"Port number: ") )

{

$result =(netstat -ano | Select-String $port | select  @{l='id';expression={$_.Pattern}} | Get-Process).ProcessName

Write-Host $result

}

Hope it helps

 


  • Edited by VBosh Thursday, September 03, 2015 9:53 AM
Free Windows Admin Tool Kit Click here and download it now
September 3rd, 2015 9:50am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics