Native PowerShell version of ping
Find the PowerShell native version of ping.
March 3, 2016
Q. Is there a native PowerShell equivalent of Ping?
A. Ping is a useful utility that tests basic connectivity between machines using ICMP (providing the target machine has the ICMP echo firewall exception enabled that enables it to respond to a ping request). While ping.exe is available in PowerShell there is a PowerShell cmdlet that has equivalent and more functionality; Test-NetConnection.
While ping primarily works using ICMP, Test-NetConnection can test a variety of TCP ports to test workload specific functionality. Basic echo functionality can be used as follows:
PS C:> Test-NetConnection savdaldc01ComputerName : savdaldc01RemoteAddress : 10.7.173.10InterfaceAlias : EthernetSourceAddress : 10.7.173.131PingSucceeded : TruePingReplyDetails (RTT) : 1 ms
Another example is to test common TCP ports, for example HTTP (port 80)
PS C:> Test-NetConnection savdalfs01 -CommonTCPPort HTTPComputerName : savdalfs01RemoteAddress : 10.7.173.175RemotePort : 80InterfaceAlias : EthernetSourceAddress : 10.7.173.131PingSucceeded : TruePingReplyDetails (RTT) : 0 msTcpTestSucceeded : True
It is also possible to test communication on other ports not defined as common ports, for example RDP (port 3389)
PS C:> Test-NetConnection savdalfs01 -Port 3389ComputerName : savdalfs01RemoteAddress : 10.7.173.175RemotePort : 3389InterfaceAlias : EthernetSourceAddress : 10.7.173.131PingSucceeded : TruePingReplyDetails (RTT) : 1 msTcpTestSucceeded : True
It's also possible to perform a quiet test that will simply return a Boolean status code of true/false based on the success.
Test-NetConnection savdalfs01 -InformationLevel Quiet
Each week, John Savill answers all of your toughest tech questions about the worlds of Windows Server, Azure, and beyond. Read his past IT advice here, and email your questions to [email protected].
About the Author
You May Also Like