Note: Article Written on Server 2012 R2 Preview Build, the functionality may change when released.
I have been waiting for years for a good replacement for what Telnet and Ping provide me. I am thrilled to announce today I discovered a legitimate replacement has come down the line! Recently Microsoft released the Preview of Server 2012 R2 and Windows 8.1. Packaged with those is PowerShell Version 4. I have not had a chance to do a deep dive into it yet. However, I have found out that there is a cool new cmdlet called Test-NetConnection.
The Test-NetConnection command does precisely what it sounds like. By default (No Parameters), the command performs a ping on internetbeacon.msedge.net, which at the time of writing, this is failing. This tool does a lot more than just ping, it also adds traceroute, and connection attempts to specified ports. Below is a snapshot of the Syntex for this cmdlet.
Let’s say we have a server running that allows Remote Desktop Connection. We know it exists. However, for some reason, connections are not working. Once you verified RDP is enabled through the console, the next step might be verifying you can get through the firewall. The way I usually approach this is by using “telnet server.name 3389″ well, the problem with this is that the server may not have the telnet client installed, that was an optional install starting in Server 2008.
I was hoping for something in PowerShell v3, but sadly nothing showed up. However, tonight I found out thanks to a Microsoft employee presenting named Bob Roudebush that this now exists! So instead of installing telnet, I can use the PowerShell cmdlet “Test-NetConnection server.name -Port 3389″. Please note that you can also use “Test-NetConnection server.name -CommonTCPPort RDP”
Let’s not stop at something that simple now, because PowerShell is all about automating. So let’s try to do something crazy. I know on my virtual lab at home, I have a few VM’s running, so let’s verify RDP is open on all of these servers. Luckily for me, most of them are joined to an Active Directory, so let’s do some magic.
(Get-ADComputer -LDAPFilter "(name=griffin*)").DNSHostName | Test-NetConnection -Port 3389
The above command pulls every computer from Active Directory (Using the Active Directory PowerShell Tools) and pipe it to Test-NetConnection, which specifies the RDP port.
Great article MattG!
How can you do a continuous ping? I haven’t found an easy way unless I am missing something basic. I sure hope they didn’t forget to add that feature as tnc will be doa without it!
I’ll have to dig around and see about this one. However keep in mind you can still use the regular ping for situations like this. The nice thing about the cmdlet is so that you can automate tasks.
Thanks for your feedback! I am one of the PMs that worked on TNC for this release but, unfortunately, there is no option for continuous ping. 🙁 We didn’t have time to implement it but it was something I really wanted too… An easy way around it is to write a quick PowerShell script with TNC in a for loop or use regular pin as MattG points out.
You could do a “while ($true) {Test-NetConnection microsoft.com}”
🙂
Test-Connection -ComputerName localhost -Count 500000
This is great. We were just talking about both tools in my training class this week. I’ll have to share this with my students.
Thanks…Mike
AwesomeSauce!!! 😀
This is a great feature, is it already aliased to a preexisting command?
IE, ping-tnc
Currently the only alias is TNC, however you can easily setup your own aliases to whatever you would like.