Test-NetConnection Cmdlet: A PowerShell-Based Ping AlternativeTest-NetConnection Cmdlet: A PowerShell-Based Ping Alternative
PowerShell's Test-NetConnection cmdlet offers more advanced capabilities than the ping command. This tutorial demonstrates the cmdlet's most useful features.
February 25, 2025

Ping is probably the most basic of all network troubleshooting tools, yet it remains widely used. Most people, including myself, use it by entering the ping command followed by a hostname or IP address. The tool sends packets to the designated host and listens for a response (see Figure 1). As such, IT professionals often use ping to check if two hosts can communicate.
Figure 1. Ping sends packets to a designated host and listens for a reply.
The Limitations of Ping
While useful, the ping command is extremely limited. Created in 1983, it has seen occasional upgrades, but its core function remains unchanged.
Figure 2. Run ping -? to display the available options for ping. The Windows version of the ping command supports multiple command-line switches.
A Powerful Alternative to Ping: Test-NetConnection
If you like the ping command but want more features, look no further than the PowerShell cmdlet Test-NetConnection. It works as a ping alternative while offering additional capabilities.
Performing a basic ping test
For a simple ping test, use Test-NetConnection followed by a hostname or IP address and set the information level to Quiet. For example, to ping Google.com, enter:
Test-NetConnection Google.com -InformationLevel Quiet
This command returns a Boolean True or False value indicating whether the ping was successful (see Figure 3). To get a more detailed output, remove the -InformationLevel Quiet switch.
Figure 3. The ping to Google.com has succeeded.
Advanced Features of Test-NetConnection
As mentioned above, this tool offers more than basic ping functionality. For example, you can check whether Windows resolves a target host's DNS name, see which DNS is being used, and view the resolved IP addresses.
Examining DNS name resolution
Using the previous example with Google.com, you can examine the DNS name resolution process by entering:
Test-NetConnection | Select-Object NameResolutionSucceeded, ResolvedAddresses, AllNameResolutionResults | Format-List
You can see what this looks like in Figure 4.
Figure 4. The Test-NetConnection tool has provided DNS name resolution data.
Replacing tracert with Test-NetConnection
The Test-NetConnection cmdlet can replace the tracert tool. Enter the hostname, followed by the -TraceRoute switch. By default, it tests up to 30 hops, but you can adjust this using the -Hops switch. Figure 5 shows a traceroute to Google.com.
Figure 5. The Test-NetConnection tool can perform a traceroute.
Testing communications across specific ports
Of all the features of the Test-NetConnection cmdlet, the one most useful is its ability to test communications across a specific port. Figure 6 illustrates this feature in action.
Figure 6. Test-NetConnection can test communications across a specific port.
For the sake of demonstration, I set up a Windows Server with the IIS role, allowing the virtual machine to function as a web server. I then configured the Windows firewall to block ICMP traffic, causing a ping test to fail. It is a typical setup for real-world web servers. Additionally, I opened port 80 but blocked port 443. This is the opposite of how the ports would be configured typically, but that's OK.
As shown in Figure 6, the Port 80 test succeeded, while the Port 443 test failed. Moreover, the Port 443 test warned that the ping test failed. Technically, while the ping test for Port 80 also failed, the warning was suppressed because the port communications test succeeded.
Using Test-NetConnection for standard ports
You can also test standard TCP ports without knowing the port number: Enter the Test-NetConnection command followed by the hostname, the -CommonTCPPort switch, and the traffic type you want to test. You can test HTTP, RDP, SMB, and WinRM traffic, as shown in Figure 7.
Figure 7. You can test common traffic types.
PowerShell object output for easier data parsing
Of course, one of the best features of this tool is that it writes its output to a PowerShell object. It allows you to format the output to suit your needs or even include it in the PowerShell pipeline without requiring you to manually parse the data, as you would have to do with the ping command.
About the Author
You May Also Like