With Windows 8.1 and Windows Server 2012, R2 Microsoft released PowerShell v4 with new PowerShell modules and new PowerShell cmdlets. One of them is the new Test-NetConnection cmdlet, which does replace some simple network tools like Ping, Traceroute, port scanner, and more.
First, if you just run Test-NetConnection, this will check a Microsoft edge server and will tell you if your internet is working or not.
You can also ping other servers.
If we have a closer look at this cmdlet, we can see that we can do much more.
What we can do is something like a port scan. In this example, I check if the RDP port is open on my webserver. Which is hopefully not ;-)
Test-NetConnection thomasmaurer.ch -CommonTCPPort RDP
You can also check for not so common ports by using the -Port parameter and entering the port number.
Another thing you could do would be a simple traceroute.
Test-NetConnection thomasmaurer.ch -TraceRoute
If you want to do a ping -t you could use the following command
while ($true) {Test-NetConnection -InformationLevel Quiet}
I hope this helps you a little :)
Find more networking PowerShell cmdlets in my PowerShell Networking cheatsheet.
Tags: Microsoft, Networking, Ping, port, Portscan, PowerShell, Test-NetConnection, Traceroute, Windows, Windows Server Last modified: June 29, 2020
TNC
absolutely forgot to mention that their is an alias called tnc :)
I’ve installed v4 on some 2008 R2 servers and it looks like this cmdlet is not part of that package. Is there any way to run this on non Windows 2012 R2 servers? If not, it won’t have value for many of us for a long time. We’ll still have to use a variety of other tools (ping, telnet, PortQry, etc) to test for connectivity.
I put PowerShell V4 on windows 7 x64 and no test-netconnection cmdlet is found…
@Joel / @MrWillieMatt:
New PowerShell functions and Modules are only added on current OS versions. PowerShell 3.0 is part of Windows 8 and Windows Server 2012. PowerShell 4.0 is part of Windows 8.1 and Windows Server 2012 R2.
Older Versions of Windows will get the new Engine without the new Functions and Modules as they rely on newer OS features.
Import-Module DnsClient
Import-Module NetTCPIP
No success on Windows 7 Enterprise:
PS C:\Windows\system32> Import-Module NetTCPIP
Import-Module : The specified module ‘NetTCPIP’ was not loaded because no valid module file was found in any module directory.
Thank you…