Get path and name of process by port

This needs to run as an administrator to get paths for all processes

This one liner gets the path of the process that is using local port 61119


([System.Diagnostics.Process]::GetProcessById((Get-NetTCPConnection -localport 61119).owningprocess)).path

This will get you a list of process identifiers (PID) sorted by local port


Get-NetTCPConnection | select localport, owningprocess | sort localport

Finally get all the ports in use by a process


Get-NetTCPConnection -owningprocess 61980 | select localport

Know a port and wonder what other ports the process is using?


Get-NetTCPConnection -owningprocess([System.Diagnostics.Process]::GetProcessById((Get-NetTCPConnection -localport 61119).owningprocess).id) | select localport

Leave a Reply

Your email address will not be published. Required fields are marked *