---
title: "Using Test-Connection in Powershell: All You Need To Know"
slug: test-connection-powershell
published: 2025-06-27T06:22:07.000Z
updated: 2025-06-27T06:22:07.000Z
feature_image: /blog/images/test-connection-powershell/test-connection-syntax-microsoft-learn.1600.webp
feature_image_alt: Microsoft Learn documentation for the Test-Connection cmdlet showing its PowerShell syntax
author: James Futhey
author_slug: james
meta_description: Learn how to use the PowerShell Test-Connection cmdlet to test network connectivity and measure response times between computers using ICMP echo requests.
status: published
---

If you've ever used the familiar ping command at the command prompt, you'll feel right at home with **Test-Connection** in PowerShell. This cmdlet is a more powerful, script-friendly version designed to test **network connectivity**, measure **latency**, and handle both simple and advanced diagnostics.

Unlike basic ping, **Test-Connection** is more versatile and works well with **pipelines, background jobs**, and custom **output** handling. Whether you're testing a single host or automating checks across hundreds of remote computers, this cmdlet gives you full control.

For more advanced network diagnostics, including port testing and detailed traceroutes, consider using PowerShell's [**Test-NetConnection** cmdlet](https://www.meetingroom365.com/blog/test-netconnection-powershell/).

## What is the Test-Connection Cmdlet?

[**Test-Connection**](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/test-connection?view=powershell-7.5) is a built-in PowerShell cmdlet that sends **ICMP echo request packets** to specified targets, typically **remote computers**, and returns their **ping response** details.

It is part of the **Microsoft.PowerShell.Management** module and supports both local and remote testing, making it ideal for quick diagnostics or embedding into broader automation scripts.

This cmdlet works similarly to traditional ping but integrates more cleanly into PowerShell workflows. You can control the number of pings, interval, timeout, and **source computers**, or even run it as a **background job** to avoid blocking other tasks.

### Syntax

```powershell
Test-Connection
[-TargetName] <string[]>
[-Ping]
[-IPv4]
[-IPv6]
[-ResolveDestination]
[-Source <string>]
[-MaxHops <int>]
[-Count <int>]
[-Delay <int>]
[-BufferSize <int>]
[-DontFragment]
[-Quiet]
[-TimeoutSeconds <int>]
[<CommonParameters>]
```

### Parameters

-   **ComputerName**: Specifies one or more **remote computers** or **IP addresses** to test.
-   **Source**: The computer or computers from which the test is initiated.
-   **\-Quiet**: Returns a **Boolean response** - only **True** or **False** based on success.
-   **\-Count**: Defines the number of **echo request packets** to send.
-   **\-BufferSize**: Controls the **packet size** in bytes.
-   **\-Delay**: Sets the interval between **ping requests** in seconds.
-   **\-TimeToLive**: Sets the **TTL value** for each ICMP packet.
-   **\-Detailed**: Returns a more **verbose response** with additional diagnostics.
-   **\-AsJob**: Runs the command as a **background job**, which can be retrieved with **Receive-Job.
-   \-TimeoutSeconds**: Specifies how long to wait for a response from each target.
-   **IPv4 / IPv6**: Forces the command to use one IP version.
-   **CommonParameters**: Includes standard PowerShell parameters like **\-Verbose, \-ErrorAction**, etc.

## Key Differences: Test-Connection vs. Test-NetConnection

While both cmdlets deal with network testing, they are **not interchangeable**. Here’s a quick comparison to clarify their roles:

| Feature | Test-Connection | Test-NetConnection |
| --- | --- | --- |
| ICMP Echo Requests | Yes | Yes |
| Port Testing | No | Yes (TCP port checking) |
| Traceroute | No | Yes |
| Cross-platform Support | Yes (PowerShell Core) | No (Windows-only) |
| Background Jobs | Yes | No |
| Detailed Network Diagnostics | Limited | More comprehensive |
| Integrated Output | Object with stats | Structured diagnostics output |

### Should You Use Test-Connection or Test-NetConnection?

Use **Test-Connection** when you need a **PowerShell-native** ping with support for **background jobs, output streaming**, and **batch testing**.

Use **Test-NetConnection** for **port-level testing, traceroutes**, or **specific connection debugging**.

## Practical Uses of the Test-Connection Cmdlet

Here are three **real-world situations** where the **Test-Connection cmdlet** is commonly used by system administrators or network engineers:

**1\. Verifying network connectivity between multiple computers in a domain**

When rolling out software updates, verifying connectivity from the source server to all target computers ensures that installations will reach their destination. This avoids delays due to **non-existent or offline computers.

2\. Measuring latency and packet loss across a high-traffic network condition**

In environments like call centers or trading floors, **latency of connections** and packet loss directly affect business operations. **Test-Connection** helps monitor **response times**, missed **ICMP echo request packets**, and **ping response quality** to proactively handle network bottlenecks.

**3\. Monitoring uptime of remote servers or network endpoints**

For infrastructure that requires high availability - like external DNS servers or **remote network share** locations - **Test-Connection** can be scripted to run on a schedule and write results to logs, providing a baseline of **network connectivity** over time.

## Prerequisites

Before using the **Test-Connection** cmdlet, ensure the following:

-   **PowerShell 7.5 or later** is installed (for the most up-to-date syntax and behavior)
-   Access to **remote computers** via ICMP is not blocked by a firewall
-   Required permissions to send ICMP **echo request packets** from the **source computer**
-   In environments requiring elevated privileges, **administrative access** might be necessary

## How to Use Test-Connection: 10 Examples

Below are practical step-by-step examples of how to use the **Test-Connection command** effectively.

### Example 1: Basic Ping Equivalent

`Test-Connection -ComputerName "8.8.8.8"`

This command sends 4 ICMP echo requests (pings) to the IP address 8.8.8.8 (Google DNS). It returns detailed information for each ping, including **Address, ResponseTime** (latency in ms), **TimeToLive (TTL)**, and **BufferSize**. It’s the PowerShell equivalent of the traditional ping but outputs objects you can further manipulate. Use this to verify if a remote host is reachable at the network level. The command reports partial results if some pings fail, allowing you to spot intermittent connectivity.

### Example 2: Ping with Custom Count

`Test-Connection -ComputerName "google.com" -Count 10`

By default, **Test-Connection** sends 4 pings. Using **\-Count 10** increases this to 10 echo requests, which provides a larger data sample. This helps detect intermittent packet loss or fluctuations in latency that a few pings might miss. The command outputs detailed round-trip times for each ping, enabling you to analyze network stability or jitter. Use this for more reliable diagnostics of network health, especially when troubleshooting inconsistent issues.

### Example 3: Quiet Mode to Return Boolean

`Test-Connection -ComputerName "192.168.1.1" -Quiet`

Adding the **\-Quiet** parameter causes the command to return only a **True** or **False** Boolean, indicating if any ping reply was received. It suppresses all verbose output. This is valuable in scripts where you want to quickly check reachability without parsing full ping details. For example, use it in conditional statements to decide on further actions based on host availability. Note that if ICMP is blocked by firewalls, this will return **False** even if the host is otherwise accessible.

### Example 4: Specify Delay Between Pings

`Test-Connection -ComputerName "server1" -Count 5 -Delay 2`

This command sends 5 pings with a **2-second** interval between each, controlled by the **\-Delay** parameter. Slowing down the requests prevents flooding network devices and helps identify issues that only appear over time, such as intermittent drops or latency spikes. The detailed output per ping lets you observe individual response times and packet loss patterns. Without **\-Delay**, pings are sent in quick succession, which may not expose transient network faults.

### Example 5: Use Traceroute with TargetName Parameter

**Heads up:** This example requires **PowerShell 6.0 or later** (i.e., PowerShell Core or PowerShell 7+). It will **not** work in Windows PowerShell 5.1.

`Test-Connection -TargetName "webserver.domain.com" -Traceroute`

In **PowerShell 6.0** and above, the **Test-Connection** cmdlet includes a -Traceroute parameter. When used with -TargetName, it performs a traceroute-style operation - showing each network hop to the destination, along with response time, IP address, and hop number - similar to the tracert command in Windows.

**Note: The -Traceroute parameter works only with -TargetName**, which accepts a string or list of hostnames/IPs. It does not work with the older **\-ComputerName** parameter, which is not part of the cross-platform implementation.

### Example 6: Set Time To Live (TTL)

`Test-Connection -ComputerName "remotehost" -TimeToLive 128`

The **\-TimeToLive** parameter limits the number of hops the ping packet can take before being discarded. Setting TTL to **128** allows the packet to traverse up to 128 routers. If the TTL is too low, the packet expires before reaching the destination, useful for diagnosing routing loops or network path length. Monitoring the TTL value in replies helps detect firewalls or devices that modify packet TTLs, which can be important for troubleshooting connectivity and security policies.

### Example 7: Use Source IP Address (for Multi-Homed Systems)

`Test-Connection -ComputerName "8.8.8.8" -Source "192.168.0.10"`

If your system has multiple network interfaces, **\-Source** forces the ping to originate from the specified local IP. This lets you verify connectivity from a particular network segment or adapter, critical in complex or segmented networks with multiple routes. For example, test if your VPN or a secondary NIC can reach the destination. If you specify an IP not assigned to your machine, the command will fail immediately.

### Example 8: Ping Multiple Hosts in One Command

`Test-Connection -ComputerName "host1", "host2", "host3"`

This sends pings to multiple hosts sequentially and groups the results by hostname. It’s a quick way to check reachability of several devices in a single command without scripting explicit loops. Each group includes latency and TTL details per ping. Use this when managing many servers or devices, helping identify which hosts respond normally and which don’t. Results can be piped or exported for monitoring and reporting.

### Example 9: Running Test-Connection Asynchronous Job

`Start-Job -ScriptBlock { Test-Connection -ComputerName "10.0.0.1" -Count 20 }`

Running **Test-Connection** as a background job prevents blocking the PowerShell prompt during long tests. You can continue working or run other commands while the pings execute. Retrieve results later with **Receive-Job -Id &lt;jobId&gt;**and check status with **Get-Job**. This approach scales for parallelizing network tests or long-duration monitoring. Remember to clean up jobs with **Remove-Job** after completion to free system resources.

### Example 10: Batch Ping Hosts from a File

`Get-Content hosts.txt | ForEach-Object { Test-Connection -ComputerName $_ -Quiet }`

This reads each line of **hosts.txt** as a hostname or IP, then runs a quiet ping on each. The **\-Quiet** flag returns a Boolean per host for quick success/failure detection. Since **Test-Connection** doesn’t accept pipeline input for **\-ComputerName**, you need **ForEach-Object** to iterate. This method is ideal for automated network audits, where you check dozens or hundreds of hosts regularly and trigger alerts or logs based on the results.

**Test-Connection** is a reliable built-in PowerShell tool for network reachability checks. Use its parameters to tailor packet counts, delays, and output formats to your needs.
