Skip to main content

Pinging Computers

In Windows 8/Server 2012 and better, there is a new cmdlet called Test-NetConnection which lets you check whether a system responds to a given port.


 
PS C:> Test-NetConnection -ComputerName powershellmagazine.com -CommonTCPPort HTTP


ComputerName           : powershellmagazine.com
RemoteAddress          : 206.217.196.220
RemotePort             : 80
InterfaceAlias         : Wi-Fi
SourceAddress          : 192.168.2.105
PingSucceeded          : True
PingReplyDetails (RTT) : 117 ms
TcpTestSucceeded       : True




PS C:> Test-NetConnection -ComputerName powershellmagazine.com -CommonTCPPort WINRM
WARNING: TCP connect to  powershellmagazine.com:5985 failed


ComputerName           : powershellmagazine.com
RemoteAddress          : 206.217.196.220
RemotePort             : 5985
InterfaceAlias         : Wi-Fi
SourceAddress          : 192.168.2.105
PingSucceeded          : True
PingReplyDetails (RTT) : 118 ms
TcpTestSucceeded       : False




PS C:> Test-NetConnection -ComputerName powershellmagazine.com -Port 445
WARNING: TCP connect to  powershellmagazine.com:445 failed


ComputerName           : powershellmagazine.com
RemoteAddress          : 206.217.196.220
RemotePort             : 445
InterfaceAlias         : Wi-Fi
SourceAddress          : 192.168.2.105
PingSucceeded          : True
PingReplyDetails (RTT) : 118 ms
TcpTestSucceeded       : False 
 

Either use -CommonTCPPort and specify a commonly used port by friendly name, or use -Port and specify a port number. Note that you will always get a response. Check TcpTestSucceeded for $true to determine whether the port responded.

If you do not specify a port, the cmdlet uses a classic ICMP ping request.

Throughout this month, we'd like to point you to two awesome community-driven global PowerShell events taking place this year:

Europe: April 20-22: 3-day PowerShell Conference EU in Hannover, Germany, with more than 30+ speakers including Jeffrey Snover and Bruce Payette, and 60+ sessions (www.psconf.eu).

Asia: October 21-22: 2-day PowerShell Conference Asia in Singapore. Watch latest annoncements at www.psconf.asia

Both events have limited seats available so you may want to register early.

Twitter This Tip! ReTweet this Tip!


Posted Jan 13 2016, 06:00 AM by ps1

upggr

I am the one