PowerShell v4 Ping and Telnet Replacement

Note: Article Written on Server 2012 R2 Preview Build, functionality may change when released.

Test-NetConnection

I have been waiting 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 really cool new cmdlet called Test-NetConnection.

Test-NetConnection does exactly what it sounds like. It is going to by default (No Parameters) perform a ping on internetbeacon.msedge.net, which at the time of writing this is failing. Now 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.

Test-NetConnection_SyntaxLets say we have an server running that allows Remote Desktop Connection, we know it exists but for some reason connections are not working. Well once you verified RDP is enabled through the console the next step might be verifying you can get through firewall. The way I normally 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 really 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 exist! So instead of installing telnet I can simply use the PowerShell cmdlet “Test-NetConnection server.name -Port 3389″. Please note that you can also use “Test-NetConnection server.name -CommonTCPPort RDP”

Test-NetConnection_Port

Lets not stop at something that simple now, because PowerShell is all about automating. So lets try to do something crazy. I know on my virtual lab at home I have a few VM’s running so lets verify RDP is open on all of these servers. Well luckily for me, most of them are joined to an Active Directory so lets do some magic.

The above command will pull every computer from Active Directory (Using the Active Directory PowerShell Tools) and pipe it to Test-NetConnection which specifies the RDP port.

I am hoping over the next few weeks that I can dig into PowerShell v4, Server 2012 R2 and Windows 8.1 so that I can provide more information on these upcoming products and the excellent new features that are a part of them.

 

Be Sociable, Share!
Leave a comment ?

10 Comments.

  1. Great article MattG!

  2. 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. :sad: 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

  3. 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

  4. AwesomeSauce!!! :grin:

  5. This is a great feature, is it already aliased to a preexisting command?

    IE, ping-tnc

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">