PowerShell provides the Test-NetConnection command or cmdlet which is equal to the ping command. The Test-NetConnection command is used to print detailed information and diagnostics about a connection and port. It supports ping test, TCP test, route tracing like traceroute or tracert command, DNS lookup, listing IP interfaces, etc.
Ping Remote Host
The Test-NetConnection command can be used without any parameter or attribute. Without any parameter or attribute this command will make ping test to the msedge.net domain name which is provided by Microsoft. The test is about simple ping.
Test-NetConnection
The output is like below.
ComputerName : internetbeacon.msedge.net RemoteAddress : 13.107.4.52 InterfaceAlias : Ethernet0 SourceAddress : 192.168.146.129 PingSucceeded : True PingReplyDetails (RTT) : 15 ms
- ComputerName is the remote system hostname that is tested and pinged.
- RemoteAddress is the remote system IP address which is tested and pinged.
- InterfaceAlias is the interface name that is used in the ping test.
- SourceAddress is the source interface IP address of the local system.
- PingSucceeded is the result of the ping test which is True in this case.
- PingReplyDetails is the ping test timing about round trip time.
Also, we can specify the remote host we want to test with ping by using the Test-NetConnection command. Just provides the remote system hostname or IP address like below.
Test-NetConnection google.com
The output is like below with the previous command output metrics.
ComputerName : google.com RemoteAddress : 216.58.206.206 InterfaceAlias : Ethernet0 SourceAddress : 192.168.146.129 PingSucceeded : True PingReplyDetails (RTT) : 57 ms
We can also specify the IP address of the remote host we want to ping or test network connectivity. In the following example we will ping the IP address 216.58.206.206 .
Test-NetConnection 216.58.206.206
Detailed Ping
The Test-NetConnection command can provide more details about the ping or testing network connectivity. The -InformationLevel is used to set the level or detail of the provided or displayed information and result. We will also provides the “Detailed” as the parameter to make detiled ping.
Test-NetConnection -InformationLevel "Detailed" google.com
the output will be like below it will provide extra detailed information like NetRoute, NameResolutionResults, etc.
ComputerName : google.com RemoteAddress : 216.58.214.142 NameResolutionResults : 216.58.214.142 InterfaceAlias : Ethernet0 SourceAddress : 192.168.146.129 NetRoute (NextHop) : 192.168.146.2 PingSucceeded : True PingReplyDetails (RTT) : 154 ms
Test TCP Connectivity and Port
The Test-NetConnection command can be used to test remote TCP port if itis accessable and open. The -Port attribute is used tiwht the port number.
Test-NetConnection -Port 443 google.com
The output will be like below. The TcpTestSucceeded provides the TCP port test result which is True in this example. This simply means it is open.
ComputerName : google.com RemoteAddress : 216.58.206.174 RemotePort : 443 InterfaceAlias : Ethernet0 SourceAddress : 192.168.146.129 TcpTestSucceeded : True
Test Remote Host Connectivity
The -ComputerName also used to set the remote hostname we want to test with the ping operation. Detailed information can be also provided with the -Information “Detailed” attribute.
Test-NetConnection -ComputerName "www.google.com" -InformationLevel "Detailed"
The output is like below.
ComputerName : www.google.com RemoteAddress : 216.58.206.164 NameResolutionResults : 216.58.206.164 InterfaceAlias : Ethernet0 SourceAddress : 192.168.146.129 NetRoute (NextHop) : 192.168.146.2 PingSucceeded : True PingReplyDetails (RTT) : 64 ms
tracert or Print Trace Route
The tracert command is popular Windows command which is used to diagnose, test and print to the network route to the specified remote host. This type of trace route information can be printed with the -DiagnoseRouting attribute.
Test-NetConnection -DiagnoseRouting google.com
The output will be like below.
ComputerName : google.com RemoteAddress : 216.58.214.142 SelectedSourceAddress : 192.168.146.129 OutgoingInterfaceIndex : 6 SelectedNetRoute : DestinationPrefix: 0.0.0.0/0 NextHop: 192.168.146.2 RouteDiagnosticsSucceeded : True
In order to get more detailed information about the trace route the PowerShell should be opened with the Administrator privileges. After this the -InformationLevel “Detailed” attribute and parameter can provided.
Test-NetConnection -DiagnoseRouting -InformationLevel "Detailed" google.com
![](/wp-content/uploads/2020/12/image-23.png)