Ping And Check Host Availability With PowerShell 7

In this blog post, I will show you how to use PowerShell 7 to ping and check host availability with advanced features.

Test-Connection

Back in the early days of Windows PowerShell, Microsoft released the test-connection cmdlet which is similar to the ping command line.

With the release of PowerShell 7, the test-connection cmdlet has received a few new features that make it much better than using the simple ping command.

Features

The test-connection cmdlet giving us the following features:

  • IPv4 or IPv6 test
  • Repat of ping without stopping after 4 attempts
  • Traceroute option built into the cmdlet as a switch
  • Timeout
  • TCP port option
  • Show source and destination

Demo

To run a simple ping test we use the following cmdlet

test-connection www.ntweekly.com -ipv4

To continue pinging the host I will add the repeat switch

test-connection www.ntweekly.com -ipv4  -repeat

To test if a port is open I will use

test-connection www.ntweekly.com  -tcpport 443

To run a traceroute at the same time I will use

Test-Connection www.ntweekly.com -Traceroute -IPv4

To ping multiple servers at the same time, I will use

Test-Connection www.ntweekly.com, www.google.com

Processing…
Success! You're on the list.

Leave a Reply

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