PowerShell Test-NetConnection

If you work as a Windows administrator, this tutorial will be of great help to you. I will explain here how to use the Test-NetConnection cmdlet in PowerShell to check connectivity from your Windows machine.

In this tutorial, I will explain everything about the PowerShell Test-NetConnection cmdlet, including its syntax and usage with examples.

What is Test-NetConnection Cmdlet?

Test-NetConnection is a PowerShell cmdlet introduced in Windows PowerShell 4.0. It combines several network diagnostic tools—such as ping, traceroute, and port checking—into a single, easy-to-use command. With Test-NetConnection, you can:

  • Check if a remote host is reachable (like a ping test)
  • Test if a specific port is open on a remote server (like telnet)
  • Trace the route taken to reach a destination (like traceroute)
  • Gather detailed network diagnostics

This cmdlet is especially useful for troubleshooting network connectivity issues, verifying if services are running, and checking firewall configurations. This is a helpful command compared to the traditional ping command for anyone working with Windows networks.

Check out PowerShell Invoke-WebRequest

Syntax of Test-NetConnection

Here’s the basic syntax for Test-NetConnection:

Test-NetConnection [-ComputerName] <string> [-Port <int>] [-InformationLevel <string>] [<CommonParameters>]
  • -ComputerName: The remote host (name or IP address) you want to test.
  • -Port: The TCP port number to check (optional).
  • -InformationLevel: Controls the amount of information returned (optional, values: ‘Detailed’, ‘Quiet’).
  • <CommonParameters>: Standard PowerShell parameters.

You can also use additional parameters for more advanced diagnostics, but for beginners, these are the most important.

Now let me show you a few examples where you can use the Test-NetConnection cmdlet.

Example 1: Basic Ping Test

To check if a remote server is reachable, simply use:

Test-NetConnection google.com

What happens:
This command sends a ping request to google.com and shows you if the host is reachable. The output includes the IP address, network interface used, and the ping status.

Example 2: Test a Specific Port

Suppose you want to check if port 80 (HTTP) is open on a web server:

Test-NetConnection google.com -Port 80

What happens:
This checks if google.com is accepting connections on port 80. You’ll see a TcpTestSucceeded property in the output, which will be True if the port is open and reachable, or False if not.

Check out Check Who Modified a File Last in Windows Using PowerShell

Example 3: Trace the Route to a Host

To see the path (hops) your connection takes to reach a server, use the -TraceRoute parameter:

Test-NetConnection google.com -TraceRoute

What happens:
This shows each hop between your computer and the destination, similar to the tracert command. It’s useful for identifying where network slowdowns or failures occur.

Example 4: Quiet Output for Scripting

If you only want to know if a connection is successful (True/False), use the -InformationLevel parameter:

Test-NetConnection google.com -Port 443 -InformationLevel Quiet

What happens:
Returns only True or False, making it perfect for use in scripts or automated checks.

Example 5: Testing Local Network Connectivity

You can also use Test-NetConnection to test connectivity to devices on your local network, such as a printer or another PC:

Test-NetConnection 192.168.1.10

What happens:
Checks if the device with IP 192.168.1.10 is reachable on your network.

Read Delete User Profiles Using PowerShell in Windows 11

Understanding the Output

A typical Test-NetConnection output includes:

  • ComputerName: The host you tested
  • RemoteAddress: The IP address of the host
  • InterfaceAlias: The network interface used
  • SourceAddress: Your local IP address
  • PingSucceeded: Whether the ping was successful
  • PingReplyDetails: Detailed ping information
  • TcpTestSucceeded: Whether the TCP port test succeeded (if specified)

This information helps you quickly identify where a connection is failing—whether it’s a network, firewall, or service issue.

Test-NetConnection With Multiple Servers

Because it returns objects, you can easily integrate Test-NetConnection into scripts. For example, to check multiple servers:

$servers = @("server1", "server2", "server3")
foreach ($server in $servers) {
    $result = Test-NetConnection $server -Port 3389 -InformationLevel Quiet
    Write-Host "$server RDP Port Open: $result"
}

This script checks if Remote Desktop (port 3389) is open on several servers.

Tips and Best Practices

  • Use Test-NetConnection instead of ping for more detailed results.
  • Use the -Port parameter to check if specific services (like HTTP, RDP, SQL) are reachable.
  • For quick checks in scripts, use -InformationLevel Quiet.
  • Use -TraceRoute to troubleshoot routing or ISP issues.

Common Errors and Troubleshooting

  • Firewall Blocking: If TcpTestSucceeded is False, the port may be blocked by a firewall.
  • Host Unreachable: If PingSucceeded is False, the host may be offline or unreachable due to network issues.
  • DNS Issues: If Test-NetConnection cannot resolve the host, check your DNS settings.
PowerShell Test-NetConnection

Conclusion

Test-NetConnection is a powerful cmdlet that brings together several essential network troubleshooting tools into one. Whether you’re checking if a website is up, verifying if a port is open, or tracing your network route, this cmdlet can help you with that. With the examples above, even beginners can start using Test-NetConnection confidently in their day-to-day troubleshooting. Do let me know if you still have any questions in the comments below.

You may also like the following tutorials:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.