Don't miss out on new posts! Sign up!

Test-NetConnection: A Comprehensive Guide to Network Connectivity Testing

Having a reliable network is crucial for businesses and individuals alike, making the test-netconnection command an invaluable tool for troubleshooting and ensuring seamless connectivity. Command line utilities have long been the staple for network technicians and server administrators alike for troubleshooting. Tools like a ping test and trace route command tests ping connectivity and routing hops between devices. However, the test-netconnection PowerShell module, often less known, provides tremendous troubleshooting capabilities. If you have experience with the more traditional command line tools, Test-NetConnection is a great tool to try. In this article, we will look at examples and questions.

Similar to Test-Connection

The Test-NetConnection cmdlet is similar to Test-Connection, which you may have used before or seen articles referencing. What is the difference? Well, Test-NetConnection is the successor to the Test-Connection cmdlet. You can see the different parameters for Test-Connection using the command:

Get-Help Test-Connection
Get help test connection
Get help test connection

Overview of Test-NetConnection

The Test-NetConnection PowerShell module is a great command line tool for testing network connectivity between one IP address and another between two devices. It has the advantage that PowerShell brings, such as being an object-based scripting language, meaning it is even more powerful when used in scripts. As a note, it is a different cmdlet than the test-connection tool shown above. 

The Test-NetConnection cmdlet shows admins the information for a connection. It supports ping tests, TCP tests, route tracing, and it also provides route diagnostics. Depending on which parameters you use, the output can include DNS lookup name results, a list of IP interfaces, IPsec rules, route/source address selection results, and it will confirm if a connection could be established.

Basic Syntax and Command Usage

It provides the capabilities to test everything from:

  • Pinging hosts for a response
  • Testing Internet connectivity
  • Testing ports like HTTP or SMB
  • Testing latency
  • Testing firewall filtering

Note the following syntax of the tool with the common parameter usage:

  • Test-NetConnection -ComputerName
  • Test-NetConnection -TraceRoute]
  • Test-NetConnection -Hops
  • Test-NetConnection -InformationLevel

Essential Features of Test-NetConnection

The Microsoft Test-NetConnection has many key features. The cmdlet supports ping test functionality, and you can test connectivity to a remote computer and analyze network health with various input parameters. Using the one test netconnection cmdlet, you can combine the functionality of multiple tools and also use the pipeline input into other cmdlets from the command.

Below is running the get-help command in the prompt:get-help test-netconnection

Note the following output of the PowerShell test-netconnection command, along with the string value options:

Get-Help Test-NetConnection
Get help test netconnection
Get help test netconnection

Testing Network Connectivity

If you want to run a basic network connectivity test to diagnose a connectivity error you are seeing on a client or server, you can simply type the command test-netconnection. In the example below, you can see the results of a network connectivity test, using ICMP. 

Running the basic test netconnection command
Running the basic test netconnection command

Note that you can use the detailed information level and receive additional information. Notice we have NameResolutionResults and the NetRoute (NextHop) displayed in addition to the information we received above.

Test-NetConnection -InformationLevel "Detailed"
Running the detailed information level
Running the detailed information level

Evaluating Port Availability

Now let’s take a look to see how we can evaluate port availability (seeing if a port is open or not).

Test-NetConnection -Port 443 -InformationLevel "Detailed"
Evaluating port availability with test netconnection
Evaluating port availability with test netconnection

The Test-NetConnection cmdlet also has a handy parameter, commontcpport, that helps to know common TCP ports without memorizing the ports they use. For instance, if you don’t remember the port number for RDP, you can use the following. Below, I am testing the connection to my domain controller, to see if the RDP port is open.

Acceptable values for this are:

  • SMB
  • HTTP
  • RDP
Test-NetConnection -commontcpport <port designation> <hostname or IP>
Testing a common port using test netconnection
Testing a common port using test netconnection

Verifying DNS Resolution

We can test DNS resolution as well, using the same test-netconnection command with the information level set to detailed. If you know an IP on the network and want to see the DNS resolution results, you can use the command 

Test-NetConnection <ip address> -InformationLevel "Detailed"
Verifying dns resolution with test netconnection
Verifying dns resolution with test netconnection

Tracing Route to a Host

Test-NetConnection allows running route diagnostics and traceroute commands. It provides detailed route diagnostics information, which is crucial for understanding network paths and identifying potential issues.

We can also use test-netconnection as a replacement for the tracert command line tool. To diagnose routing issues, we can use the command:

test-netconnection <ip address> -diagnoserouting
Getting detailed routing info with test netconnection
Getting detailed routing info with test netconnection

If you want more details on the routing paths, metrics, etc, you can add the -informationlevel “detailed”

test-netconnection <ip address> -diagnoserouting -informationlevel "detailed"
Getting detailed routing information with test netconnection
Getting detailed routing information with test netconnection

We can also add the -traceroute parameter to have the more traditional traceroute functionality from the command line:

test-netconnection <IP or hostname> -traceroute
Adding the traceroute command into the syntax of test netconnection
Adding the traceroute command into the syntax of test netconnection

Scripting with Test-NetConnection

You can also write quick and easy scripts that use Test-NetConnection.

This script will check the connectivity to a specified remote server and provide basic information about the connection:

# PowerShell script using Test-NetConnection

# Specify the remote host to test connectivity with
$remoteHost = ""

# Perform the test
$testResult = Test-NetConnection -ComputerName $remoteHost

# Output the result
if ($testResult.PingSucceeded) {
    Write-Host "Ping to $remoteHost successful."
    Write-Host "Latency: $($testResult.Latency)ms"
} else {
    Write-Host "Ping to $remoteHost failed."

# Optional: Add more detailed diagnostics if needed
# This will show more detailed information about the connection
# Remove the comment '#' in the next line to enable this
# $testResult | Format-List *

This script performs a basic ping test to check if the specified remote host ( in this example) is reachable. It then outputs whether the ping was successful and shows the latency if the ping succeeded. You can replace "" with the actual host you want to test. Additionally, you can uncomment the last line to get more detailed information about the network test.

FAQs on Test-NetConnection

How Can Test-NetConnection Help in Testing Specific TCP Port Connectivity?

Test-NetConnection is invaluable for checking the status of specific TCP ports on a target computer or remote host. By specifying a TCP port number, users can determine whether a particular service, like a web server, is reachable and operational aside from simple pings. This feature is useful in verifying network service availability and security.

What Makes Test-NetConnection a Preferred Choice for PowerShell Network Diagnostics?

Unlike traditional ping commands, it offers extensive diagnostic capabilities including TCP testing, route diagnostics, and DNS lookup results. The cmdlet returns basic information for quick checks and detailed data for in-depth analysis, making it a comprehensive tool for network diagnostics.

Can Test-NetConnection Perform Route Tracing Similar to Traceroute?

Yes, ‘Test-NetConnection’ can perform route tracing, providing functionality similar to the traceroute command. It maps the route packets take to a destination address, offering insights into the network path and helping diagnose routing issues.

In What Ways Can Test-NetConnection Be Used for Remote Server Diagnostics?

‘Test-NetConnection’ is highly effective for diagnosing remote server issues. It can test connectivity to a remote server, analyze TCP port accessibility, and provide route diagnostics. This cmdlet is useful in scenarios where understanding the connectivity and route path to a remote server is critical.

How Does Test-NetConnection Assist in Understanding Network Connection Establishment?

‘Test-NetConnection’ sheds light on the process of network connection establishment by displaying information on the attempted connections to a target host. This includes indicating successful or failed connection attempts.

Is Test-NetConnection Capable of Providing Detailed Network Diagnostic Information?

Absolutely. ‘Test-NetConnection’ tests network connectivity and provides a wealth of diagnostic information. This includes route diagnostics information, TCP connectivity details, and DNS resolution data. Depending on the specified parameters, the cmdlet can output basic information for an overview or detailed data for comprehensive analysis.

How Does Test-NetConnection Facilitate Network Troubleshooting at the Command Prompt?

Using ‘Test-NetConnection’ at the command prompt simplifies network troubleshooting. It enables users to quickly assess network connectivity, perform ping tests, and run detailed diagnostics all from a single command. This makes it an efficient tool for identifying and resolving network issues directly from the command prompt.

Test-NetConnection Key Takeways

The Test-NetConnection cmdlet is an extremely powerful tool to troubleshoot or verify network connectivity between hosts, IPs, and across the Internet. You can easily narrow in on port filtering or routing issues using the cmdlet.

Don't miss out on new posts! Sign up!

Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at and has over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, Brandon has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family.

Related Articles

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.