Skip navigation

Native PowerShell version of ping

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 savdaldc01


ComputerName : savdaldc01
RemoteAddress : 10.7.173.10
InterfaceAlias : Ethernet
SourceAddress : 10.7.173.131
PingSucceeded : True
PingReplyDetails (RTT) : 1 ms

Another example is to test common TCP ports, for example HTTP (port 80)

PS C:\> Test-NetConnection savdalfs01 -CommonTCPPort HTTP


ComputerName : savdalfs01
RemoteAddress : 10.7.173.175
RemotePort : 80
InterfaceAlias : Ethernet
SourceAddress : 10.7.173.131
PingSucceeded : True
PingReplyDetails (RTT) : 0 ms
TcpTestSucceeded : 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 3389


ComputerName : savdalfs01
RemoteAddress : 10.7.173.175
RemotePort : 3389
InterfaceAlias : Ethernet
SourceAddress : 10.7.173.131
PingSucceeded : True
PingReplyDetails (RTT) : 1 ms
TcpTestSucceeded : 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 john@savilltech.com.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish