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
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
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
IPv4 | IPv6
IPv6 is on the rise, so you can specify the protocol.
Test-Connection -TargetName 8.8.8.8 -Count 1 -IPv6
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
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
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
Ok, that’s it for today. Have a nice week and see you next time with PowerShell.
Categories: PowerShell, Windows 10, Windows Server
I like the “Test-Connection -TargetName 8.8.8.8 -ResolveDestination -Traceroute“ example but in 99% of all cases I am gonna stick with the good old ping 😀
LikeLiked by 1 person