When an application cannot reach a database, a website fails to load, or Remote Desktop refuses to connect, traditional tools like ping only tell part of the story. Many firewalls block ICMP ping packets completely while leaving application ports wide open—or vice versa.

PowerShell solves this with Test-NetConnection, a built-in diagnostic cmdlet that combines ping, TCP port testing, DNS lookup, traceroute, and routing diagnostics into a single command. This guide walks through practical ways to test connectivity, check specific ports, and automate checks across multiple servers.

What Is Test-NetConnection?

Test-NetConnection (part of the built-in NetTCPIP module in Windows) inspects network connectivity at multiple layers and returns structured PowerShell objects rather than plain text. Depending on the parameters you pass, it can check:

  • ICMP Reachability: Standard ping tests with round-trip latency (RTT) and DNS resolution details.
  • TCP Port Availability: Whether a specific TCP port (such as 443, 3389, or 1433) is open and accepting connections.
  • Common Service Ports: Quick tests using friendly names like HTTP, RDP, SMB, or WINRM instead of memorizing port numbers.
  • Path & Route Diagnostics: Hop-by-hop traceroute paths and local source interface/route selection.

Prerequisites

  • Operating System: Windows 10, Windows 11, or Windows Server 2012 R2 and newer (includes the NetTCPIP module by default).
  • PowerShell Version: Windows PowerShell 5.1 or PowerShell 7+ on Windows.
  • Permissions: Standard user permissions work for ping, TCP port, and traceroute checks. Administrator privileges are only required if you inspect local IPsec rules with -InformationLevel Detailed.

Step 1: Run a Basic Connectivity and DNS Check

To verify basic internet or host reachability along with DNS resolution, run Test-NetConnection followed by a hostname or IP address:

Test-NetConnection -ComputerName "www.microsoft.com"

Look at two key fields in the output:

  • RemoteAddress: Confirms DNS resolved the hostname to an IP address.
  • PingSucceeded: Shows True if ICMP echo replies succeeded, or False if the host is unreachable or blocking ICMP.

Tip: Running Test-NetConnection with no parameters tests connectivity to Microsoft’s default internet beacon (internetbeacon.msedge.net), making it a fast one-word check for general internet access.

Step 2: Test If a Specific TCP Port Is Open

Even when PingSucceeded returns False because a firewall drops ICMP packets, you can verify whether a specific service port is reachable using the -Port parameter.

Test by Port Number

For example, to test HTTPS connectivity (port 443) or SQL Server (port 1433) on a remote host:

Test-NetConnection -ComputerName "sql01.corp.local" -Port 1433

Check the TcpTestSucceeded line at the bottom of the output:

  • TcpTestSucceeded : True — The TCP three-way handshake succeeded; the port is open and listening.
  • TcpTestSucceeded : False — The connection timed out or was refused; a firewall, network ACL, or stopped service is blocking traffic.

Test Common Windows Ports by Name

Instead of typing port numbers for standard administrative services, use the -CommonTCPPort parameter with HTTP (80), RDP (3389), SMB (445), or WINRM (5985):

Test-NetConnection -ComputerName "fileserver01" -CommonTCPPort SMB

Step 3: Trace Network Hops and Diagnose Routing

When a connection fails or feels unusually slow, you can trace each router hop along the path or check which local network adapter Windows selects.

# Trace the network path to a destination
Test-NetConnection -ComputerName "8.8.8.8" -TraceRoute

# Inspect local source IP, interface, and next-hop route selection
Test-NetConnection -ComputerName "www.microsoft.com" -DiagnoseRouting -InformationLevel Detailed

Note: -DiagnoseRouting is especially helpful on servers with multiple NICs or active VPN connections, as it shows the exact source IP address and gateway Windows chose to reach the target.

Step 4: Automate Multi-Server Port Checks in Scripts

Because Test-NetConnection outputs objects, you can use -InformationLevel Quiet to return a clean True or False boolean value and loop through multiple servers at once:

$Servers = @("DC01", "DC02", "APP01", "SQL01")

$Results = foreach ($Server in $Servers) {
    [PSCustomObject]@{
        Server       = $Server
        Port443Open  = Test-NetConnection -ComputerName $Server -Port 443 -InformationLevel Quiet -WarningAction SilentlyContinue
        Port3389Open = Test-NetConnection -ComputerName $Server -Port 3389 -InformationLevel Quiet -WarningAction SilentlyContinue
    }
}

$Results | Format-Table -AutoSize

Step 5: Verify Your Results

Confirm that your troubleshooting test accurately reflects firewall and service behavior:

  1. Run the script or single-port command against a known working server (such as your local Domain Controller on port 389 or 445) and verify that TcpTestSucceeded returns True.
  2. Test an intentionally unused high port (such as 59999) on the same host and confirm that TcpTestSucceeded returns False.

Best Practices for PowerShell Network Diagnostics

  • Remember TCP-Only Limitation: Test-NetConnection -Port only tests TCP ports. It cannot verify UDP services like DNS (UDP 53), NTP (UDP 123), or SNMP (UDP 161).
  • Suppress Warning Clutter in Loops: Failed port checks emit a yellow warning banner by default. Add -WarningAction SilentlyContinue in automated scripts so output tables stay clean.
  • Use Fast .NET Sockets for Large Port Scans: Each failed Test-NetConnection call waits several seconds for a TCP timeout. If you need to scan dozens of servers or wide port ranges, use System.Net.Sockets.TcpClient with a short millisecond timeout instead.

Warning: Only run automated port scans against servers and networks you own or have explicit authorization to test, as repeated connection attempts can trigger Intrusion Detection Systems (IDS).