powershell command for network diagnostics


Test-NetConnection are useful in many ways

To get detail information 

Test-NetConnection -ComputerName www.contoso.com -InformationLevel Detailed 

To check for TraceRoute - shows you the path to the destination server, in this case www.contoso.com.

As traceroute operates on layer 3, it will be good to ensure connectivity is good, before proceeding to troubleshoot network connectivity at a higher level like DNS. (layer 7).


Test-NetConnection -ComputerName www.contoso.com -TraceRoute

Route diagnostics 

Test-NetConnection -ComputerName www.contoso.com -DiagnoseRouting -InformationLevel Detailed

or if you want to limit it to a specific network adapter (constraint interface)

Test-NetConnection -ComputerName www.contoso.com -ConstrainInterface 6 -DiagnoseRouting -InformationLevel Detailed


To get your adapter, you can run "Get-NetAdapter"


Test-Connection is another useful utility. This is a ICMP request. ICMP works on layer 3 of the TCPIP and are not associated to any ports. Ports are for layer 4. 

To test for a connectivity to a server, you can try to use 

Test-Connection -TargetName www.google.com -Traceroute

This provides routing information which can be handy. 

However it can also be used to test connectivity for a specific port.

Test-Connection bing.com -TCPPort 443 -Detailed -Count 4


Route diagnostic 

To perform route diagnostic you can try this command. You need to be running as an administrator otherwise you get very little information

Test-NetConnection -ComputerName www.contoso.com -DiagnoseRouting -InformationLevel Detailed

Sample output are shown below:-




Resolve-DnsName

To resolve a host 

resolve-dnsname test.com

Sometimes people tend to put things in the host file and that can be an issue sometimes. To do dns lookup without using local host file, 

resolve-dnsname test.com -NoHostsFile

To resolve dns against another dns server

resolve-dsname test.com -Server my-custom-dns-server

In the window network, it falls back to using netbios. To avoid that, use 

resolve-dnsname test.com -DnsOnly

For more information, please use this link

https://learn.microsoft.com/en-us/powershell/module/dnsclient/resolve-dnsname?view=windowsserver2022-ps

There are other commands that might be of interest such as Get-NetTCPConnection, Get-NetRoute and Find-NetRoute

Proxy connectivity


To test for proxy you can use Invoke-WebRequest command

$myCreds=New-Object System.Management.Automation.PSCredential -ArgumentList "Domain\name",$secPasswd

Invoke-WebRequest -URI www.google.com -Proxy 'http://ipadress:port' -ProxyCredential $mycreds





Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm