dcsimg
Read more on "Server OS Spotlight" »

PowerShell's Test-NetConnection a Versatile Tool for Network Diagnostics

By Eric Geier (Send Email)
Posted October 30, 2013


Among many other user and admin improvements in Windows 8.1 and Windows Server 2012 R2 is PowerShell version 4.0. In this month's Server Tutorial we'll discover a new cmdlet for PowerShell called Test-NetConnection (TNC), available in both Windows 8.1 and Windows Server 2012 R2.

It can be used for testing ICMP and TCP connectivity among end users, servers and other network targets. Windows Server 2012 R2 Tutorials While it can be used as a simple ping utility, with the right commands and scripting it can also replace tools like nslookup and tracert, and even provide much more powerful troubleshooting and management capabilities than that.

Let's get started by entering tnc without parameters in a PowerShell window and perform a ping on internetbeacon.msedge.net. Here's an example output:

ComputerName : internetbeacon.msedge.net
RemoteAddress : 131.253.3.197
InterfaceAlias : LAN1
SourceAddress : 192.168.3.128
PingSucceeded : True
PingReplyDetails (RTT) : 25 ms

Then adding a IP address or domain will return a ping upon that address; for instance, tnc egeier.com returned the following output:

ComputerName : egeier.com
RemoteAddress : 64.40.151.4
InterfaceAlias : LAN1
SourceAddress : 192.168.3.128
PingSucceeded : True
PingReplyDetails (RTT) : 34 ms

For additional details you can add the InformationLevel parameter. For instance, tnc egeier.com -informationlevel detailed will add AllNameResoultionResults and NetRoute (NextHop) to the output:

ComputerName : egeier.com
RemoteAddress : 64.40.151.4
AllNameResolutionResults : 216.177.143.135
64.40.151.4
InterfaceAlias : LAN1
SourceAddress : 192.168.3.128
NetRoute (NextHop) : 192.168.3.2
PingSucceeded : True
PingReplyDetails (RTT) : 47 ms

And if the connectivity test fails, it can offer some additional clues that can help you identify and fix the issue.

To add the list of hosts on the path to the specified target, enter the TraceRoute parameter. For instance, tnc egeier.com -traceroute returned the following:

ComputerName : egeier.com
RemoteAddress : 64.40.151.4
InterfaceAlias : LAN1
SourceAddress : 192.168.3.128
PingSucceeded : True
PingReplyDetails (RTT) : 46 ms
TraceRoute : 192.168.3.2
TimedOut
TimedOut
TimedOut
TimedOut
TimedOut
TimedOut
TimedOut
TimedOut
TimedOut
TimedOut
TimedOut
64.40.151.4

(As you see, our TraceRoute pings timed out, probably due to running Windows Server 2012 R2 inside a VM.)

To test TCP connectivity you can add the Port parameter to test connectivity via a specified port; for instance, tnc egeier.com -port 80. And to test via common TCP ports like HTTP, RDP and SMB you can simply enter the keyword instead of the port number. For instance, tnc egeier.com http will perform the same test as the previous:

ComputerName : egeier.com
RemoteAddress : 64.40.151.4
RemotePort : 80
InterfaceAlias : LAN1
SourceAddress : 192.168.3.128
PingSucceeded : True
PingReplyDetails (RTT) : 35 ms
TcpTestSucceeded : True

Since the output of TNC includes the relevant WMIv2 objects of the local machine, you can script against them using commands as well. As an example, you could use the NetAdapter output that's passed when using TNC to rename the network adapter: tnc egeier.com | Rename-NetAdapter -NewName "LAN Adapter Name"

We've reviewed some of the very basic TNC functionality and commands. For further details and help, try running the get-help tnc command or check out the Microsoft online resources.


Eric Geier is a freelance tech writer — keep up with his writings on Facebook. He's also the founder of NoWiresSecurity, a cloud-based Wi-Fi security service, and On Spot Techs, an on-site computer services company.

Follow ServerWatch on Twitter and on Facebook

Page 1 of 1

Read more on "Server OS Spotlight" »

Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.