We all have been there, we want to set up a new application or agent which needs network access and needs to reach an endpoint using a specific port, but it simply doesn't work. So as a server admin, we need to have a tool to troubleshoot network connectivity issues on Windows Server to figure out is DNS working, is the remote endpoint even reachable, is the port open, and many other things. Luckily, Windows Server comes with PowerShell and has build-in cmdlets to help with that. My favorite PowerShell cmdlet to troubleshoot network connectivity issues is Test-NetConnection.
The Test-NetConnection cmdlet displays diagnostic information for a connection. It supports ping test, TCP test, route tracing, and route selection diagnostics. Depending on the input parameters, the output can include the DNS lookup results, a list of IP interfaces, IPsec rules, route/source address selection results, and/or confirmation of connection establishment.
You can do simple things, like just testing ping connectivity:
Test-NetConnection itopstalk.com
But you can also get some more detailed information on the connectivity:
Test-NetConnection itopstalk.com -InformationLevel "Detailed"
However, there is more! One of the commands I need the most, especially when working with web services, is to test a specific TCP port.
Test-NetConnection itopstalk.com -Port 443 -InformationLevel "Detailed"
You can also perform route diagnostics to connect to a remote host.
Test-NetConnection -ComputerName itopstalk.com -DiagnoseRouting -InformationLevel Detailed
If you want to learn more about the Test-NetConnection cmdlet to troubleshoot network connectivity issues, check out Microsoft Docs.
Test-NetConnection is part of Windows PowerShell 5.1 and is available on Windows Server as well as on Windows 10. If you are running PowerShell 7, there is a cross-platform cmdlet called Test-Connection, which provides you with similar capabilities.
I hope this was helpful, and if you have any questions, feel free to leave a comment. What are your favorite PowerShell cmdlets to troubleshoot network connectivity issues?