Test-Connection
Ping a host
Test-Connection -ComputerName 1.1.1.1 -Count 2
- Works on
- WindowsLinuxmacOS
- PowerShell
- 5.1 and later
- Reference
- Microsoft Learn: Test-Connection
- PowerShell 5.1 Windows only. Returns Win32_PingStatus objects; the time is in ResponseTime.
- PowerShell 7 Works everywhere. Results have Latency and Status columns, and -ComputerName is an alias for -TargetName.
What you'll see
Destination: 1.1.1.1
Ping Source Address Latency BufferSize Status
(ms) (B)
---- ------ ------- ------- ---------- ------
1 MY-LAPTOP 1.1.1.1 12 32 Success
2 MY-LAPTOP 1.1.1.1 11 32 Success
Ping. -Count 2 keeps it short. In PowerShell 7, -TargetName is the modern parameter name. -ComputerName still works on Windows PowerShell 5.1.
This is ICMP. A host can be up and still block ping.
Try this
Test-Connection -ComputerName localhost -Count 1
Coming from another shell
| Shell | What you might type |
|---|---|
| bash / zsh | ping -c 2 1.1.1.1 |
| cmd.exe | ping -n 2 1.1.1.1 |
More in From bash and From cmd.