Tag Archives: Scripting

List Open UDP Ports Using Powershell

In the last post I showed how to list open TCP ports using Powershell. Unlike the netstat command in DOS, Powershell splits TCP and UDP into two different commands, Get-NetTCPConnection and Get-NetUDPEndpoint. Here are some examples of Get-NetUDPEndpoint.

Get-NetUDPEndpoint by itself will return the local address and local port


To show listening ports filter for the address

Get-NetUDPEndpoint | Where {$_.LocalAddress -eq ""}

To view the owning process ID, add the OwningProcess field.

Get-NetUDPEndpoint | Where {$_.LocalAddress -eq ""} | select LocalAddress,LocalPort,OwningProcess

And use this command to display the name of the owning process.

Get-NetUDPEndpoint | Where {$_.LocalAddress -eq ""} | select LocalAddress,LocalPort,@{Name="Process";Expression={(Get-Process -Id $_.OwningProcess).ProcessName}}

In my next post I will demonstrate combining Get-NetTCPConnection and Get-NetUDPEndpoint into a single command.

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 

Schedule a Defrag to Run Automatically

Scheduling a defrag of your hard drive can help to improve the performance of your computer and remove the burden of remembering to do it yourself. This guide will show you how to set up a scheduled defrag in Windows XP.

Defragging (or defragmenting) is the process of rearranging files on your hard drive so that they take up one contiguous space instead of being spread out in multiple places across the drive. This can speed up system performance since the drive heads don’t have to jump around to read a file and can access it all in one shot. It is a good idea to defragment your hard drive regularly, but it’s tough to remember and if you start it manually while you’re using your computer, then it really slows everything down until it’s done, and may not even run at all while other applications are running. It would be nice to be able to schedule the defragment process to run while you were away from your computer so you never have to think about it.

Continue reading →