Life's random bits By b1thunt3r (aka Ishan Jain)…
Troubleshooting Network with PowerShell

Troubleshooting Network with PowerShell

Ishan jain
Network troubles, PowerShell to the rescue.

There are times when you need to do some network troubleshooting in Windows beyond just simple ping or tracert.

Best practice today is to block ICMP packages, to prevent DDoS attacks, but the downside of that is you cannot troubleshoot network related issues. Also your Windows installation might not have telnet installed. Sometimes, you might not be even able to load your favorite network trouble shooting tool either for various reasons.

One of the concepts one can use is to try to connect to a TCP port on the remote machine, granted that it has an TCP port open. In most cases 3389/RDP is open on most Windows Pro and Enterprise by default.

You can find a nifty PowerShell command, Test-NetConnection, as part of the NetTCPIP PowerShell module.

To check TCP port connectivity:

Test-NetConnection -TraceRoute -ComputerName <computer_name> -Port <tcp_port>

Where:

  • computer_name: Remote computer name or IP
  • tcp_port: TCP port number

For Example, you can use the following command to check connectivity for port 3389 on a remote windows machine:

Test-NetConnection -TraceRoute -ComputerName windows.example.com -Port 3389

Other uses

Test-NetConnection can also be used for troubleshooting with ICMP:

Test-NetConnection -ComputerName <computer_name>
Test-NetConnection -TraceRoute -ComputerName <computer_name>
Test-NetConnection -DiagnoseRouting -ComputerName <computer_name>

Docmentation for Test-NetConnection has more scenarios with examples.

Recources