List Open Ports Using Powershell

In a previous post I showed how to use the netstat command to show open ports. This is another way using Powershell which gives you more options.

Get-NetTCPConnection is the Powershell equivalent to netstat and by itself will return a similar output to netstat.


To show only the listening ports we need to filter for all items in the Listen state with the remote address of

get-nettcpconnection | where {($_.State -eq "Listen") -and ($_.RemoteAddress -eq "")}

You can add additional fields like the process ID for each port. Changing the fields from the default requires selecting each one you want and then piping to ft (format-table).

get-nettcpconnection | where {($_.State -eq "Listen") -and ($_.RemoteAddress -eq "")} | Select LocalAddress,LocalPort,RemoteAddress,RemotePort,State,OwningProcess | ft

This example will get the name of the process associated with each item.

 get-nettcpconnection | where {($_.State -eq "Listen") -and ($_.RemoteAddress -eq "")} | select LocalAddress,LocalPort,RemoteAddress,RemotePort,State,@{Name="Process";Expression={(Get-Process -Id $_.OwningProcess).ProcessName}} | ft 

Leave a Reply

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