Last monthsi am working a lot with network issues. One of my favorite tools is the Test-NetConnection command from PowerShell.
Test-Net Connection is a command that can use to troubleshoot networking issues and find out the source of the problem.
Today I would like to explain how can use the command and which capabilities it has.
Let's start !!
Below you can find different scenarios that you can use the Test-NetConnection command, but you can't limit only to these scenarios.
You can simple
#Scenario 1 - Check the connectivity to specific Site or Public IP Address
Test the ping reply and get details regarding the IP Address of a website
Test-NetConnection -ComputerName www.google.com
However you can use the same command to get more details including the parameter -Information
Test-NetConnection -ComputerName www.google.com -InformationLevel Detailed
#Scenario 1 - Check the connectivity to specific Server
Let's see how can use the command to verify connectivity with a Server.
Test-NetConnection -ComputerName <Server/IP Address>
#Scenario 2 - Check if you have connectivity to a Server in specific Port
This command check if the Server has open specific Port.
It's very useful when you want to verify that a Windows, Server has access to another Server in a specific Port.
Test-NetConnection -ComputerName <Server/IP Address> -Port 443
#Scenario 3 - Check your routing from a PC to a Server
The command perform a route diagnostic to a specific server.
Test-NetConnection -ComputerName <Server/IP Address> -DiagnoseRouting -InformationLevel Detailed
#Scenario 4 - Diagnose your routing from a PC with specific network interface to a Server
Let's see how can perform a route diagnostic to a specific server from a specific network interface.
If you have multiple network interfaces in a Server/Workstation that you want to perform a test the following command can fill your needs.
First run the Get-NetIPAddress to get a list with your Network Interfaces including the ifIndex.
After that you can run the following command including the Parameter -ConstrainInterface with the ifIndex of the network interface.
Test-NetConnection -ComputerName <Server/IP Address> -DiagnoseRouting -ConstrainInterface 12 -InformationLevel Detailed
#Scenario 5 - Perform a Trace Route from one Endpoint to another.
Last you can use the parameter -TraceRoute to find out the routing of your Server until google.com.
However, this command you can use it to traceroute from one Server to another in your network.
Test-NetConnection -ComputerName www.google.com -TraceRoute
If you want to allow only specific hops with the -TraceRoute then you can use the parameters -Hops including the number of the Hops that you want to run.
Test-NetConnection -ComputerName www.google.com -TraceRoute -Hops 3
You can find more parameters to run depends of your troubleshooting issue.
However, i found the above commands the most useful in different troubleshooting scenarios .
I hope to help you learn something today that you will use it in your day to day tasks.