How to traceroute using PowerShell?


Traceroute is the way to determine the hopes that the packets are passing through when requested. In the command prompt, that utility is called the tracert and we can also use that utility to trace the network packets. For example,

PS C:\> tracert google.com
Tracing route to google.com [216.58.203.142]
over a maximum of 30 hops:
1    1 ms    1 ms    1 ms 192.168.0.1
2    2 ms    2 ms    2 ms 45.114.51.246
3    8 ms    4 ms    4 ms 103.210.200.141
4    21 ms   *       * 10.10.125.29
5    6 ms    6 ms    6 ms 72.14.196.213
6    14 ms   26 ms   25 ms 108.170.248.161
7    11 ms   7 ms    6 ms 209.85.248.27
8    6 ms    6 ms    6 ms bom05s10-in-f142.1e100.net [216.58.203.142]
Trace complete.

The above example shows there is a total of 8 intermediate hops that the packet passes through to resolve the destination address.

We can also use the above utility for the local servers.

PS C:\Users\Administrator> tracert AD Tracing route to AD.automationlab.local [192.168.0.200]
over a maximum of 30 hops:
1 <1 ms <1 ms <1 ms AD [192.168.0.200] Trace complete.

Another method to determine the network packet route is through the Test-NetConnection command which supports the TraceRoute parameter.

PS C:\> Test-NetConnection -ComputerName google.com -TraceRoute
ComputerName           : google.com
RemoteAddress          : 172.217.167.174
InterfaceAlias         : Ethernet0
SourceAddress          : 192.168.0.200
PingSucceeded          : True
PingReplyDetails (RTT) : 5 ms
TraceRoute             : 192.168.0.1
                         45.114.51.246
                         0.0.0.0
                         0.0.0.0
                         72.14.196.213
                         108.170.248.161
                         108.170.232.203
                         172.217.167.174

This is the advanced utility and we can also set the maximum number of hops to pass. For example,

PS C:\> Test-NetConnection -ComputerName google.com -TraceRoute -Hops 2
WARNING: Trace route to destination 172.217.167.174 did not complete. Trace terminated :: 45.114.51.246
ComputerName           : google.com
RemoteAddress          : 172.217.167.174
InterfaceAlias         : Ethernet0
SourceAddress          : 192.168.0.200
PingSucceeded          : True
PingReplyDetails (RTT) : 6 ms
TraceRoute             : 192.168.0.1
                         45.114.51.246

To get only traceroute hopes, you can select the TraceRoute parameter.

Test-NetConnection -ComputerName google.com -TraceRoute | Select -ExpandProperty
TraceRoute

Updated on: 18-Jan-2021

12K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements