PowerShell

Test-Connection (ping) with PowerShell 7

In one of my previous articles I dedicated myself to the modern version of ping called Test-Connection. I recently discovered that the cmdlet in PowerShell Core 7 offers more parameters than in Windows PowerShell. So I decided to take a deeper look at Test-Connection with PowerShell 7 that I now want to share with you.

My previous article was written some time ago, more precisely in 2017. You can find the article here: The modern version of ping: Test-Connection

Now the time has come to dedicate myself to PowerShell 7 to carry out some awesome things with Test-Connection. If you haven’t installed PowerShell 7 yet, you can easily do it with a one-liner.


iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -Preview"

Ready? Let’s jump in.

TargetName

Unlike Windows PowerShell, PowerShell 7 provides the TargetName parameter and the ComputerName parameter to specify the remote host.


Test-Connection -TargetName sid-500.com,8.8.8.8

Bild1.png

Count

As in Windows PowerShell, you can specify how often the ping will be performed.


Test-Connection -TargetName sid-500.com,8.8.8.8 -Count 1

Bild2.png

Quiet

Windows PowerShell as well as PowerShell 7 provide omitting the output to show only true or false depending on whether the ping is successful or not.


Test-Connection -TargetName sid-500.com,8.8.8.8 -Count 1 -Quiet

Bild3.png

IPv4 | IPv6

IPv6 is on the rise, so you can specify the protocol.


Test-Connection -TargetName 8.8.8.8 -Count 1 -IPv6

Bild4.png

Infinite Ping

Do you remember ping.exe -t ? Here it is with PowerShell 7. The ping is send continously.


Test-Connection -TargetName sid-500.com -Repeat

Bild5.png

Resolve DNS Name | Tracert | TraceRoute

The ResolveDestination parametet tries to resolve the DNS-Name. You can either try to retrieve the IP-Adresse (Forward Lookup) or the hostname (Reverse-Lookup).

Watch out line 1. It shows the dns name of 8.8.8.8


Test-Connection -TargetName 8.8.8.8 -ResolveDestination

Bild6.png

Now we go one further. When ResolveDestionation is used along with the TraceRoute parameter, PowerShell tries to resolve the dns name of all the hosts along the way to the target. Wow.


Test-Connection -TargetName 8.8.8.8 -ResolveDestination -Traceroute

Bild7.png

Ok, that’s it for today. Have a nice week and see you next time with PowerShell.

1 reply »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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