Test-NetConnection is a PowerShell cmdlet that checks and then displays diagnostic information about a network connection, whether to another computer on the same network or a web server on the internet. It does not only PING test, like the old school PING command line but much more.
Here are some examples of using this cmdlet that you may not know before.
Check Internet connection
Instead of finding a website to ping to see if you have the internet connection, simply run the command without any parameters.
What it does is to PING an internet beacon and display the result whether it’s successful or not.
Tells your local IP address
See the SourceAddress from the screenshot above? That’s your local IP address. Running the following command even tells you what your router’s IP address is.
Test-NetConnection -InformationLeve "Detailed"
While it seems useless when you only have one IP address, it will be very useful when you have multiple network adapters, such as one wired adapter with one wifi access. Not only does it tell you which source IP is used to do the connection test, but with parameters like ConstrainSourceAddress or ConstrainInterface, you can also tell which one to use to perform the test.
Pinging is the most common way to test the network connection but when ICMP is disabled, the next reliable way is to test the network port.
Test-NetConnection www.nextofwindows.com -Port 443
You can even use the port name if you like.
Test-NetConnection www.nextofwindows.com -CommonPortName HTTP
However, you can only the following port names are accepted.
Guess what, you can just do a TraceRoute with Test-NetConnection to list all the network hops used to travel to the target computer.
Test-NetConnection www.nextofwindows.com -TraceRoute
How about running a diagnosis?
Test-NetConnection www.nextofwindows.com -DiagnoseRouting