For Windows System Administrator, Network troubleshooting is a part of the system troubleshooting. Maybe you need to check the IP address of a machine or test if its networking connection is working. Maybe you need to see if DNS is properly configured or check the latency between two hosts.
You can run the command [cc]Get-Command -Module Net* | Group Module[/cc] to check all the Network command available on your PowerShell. But more important than knowing every one of them, is to know the most useful cmdlets that have the potential to replace those old commands that you can’t live without.
Below is Windows Powershell equivalents for some networking commands:
IPCONFIG
Description: This command has many options, but the most common usage is just to show the IP address, subnet mask and default gateway for each network adapter in a machine.
PowerShell: Get-NetIPConfiguration or Get-NetIPAddress
Sample command lines:
Get-NetIPConfiguration
Get-NetIPAddress | Sort InterfaceIndex | FT InterfaceIndex, InterfaceAlias, AddressFamily, IPAddress, PrefixLength -Autosize
Get-NetIPAddress | ? AddressFamily -eq IPv4 | FT –AutoSize
Get-NetAdapter Wi-Fi | Get-NetIPAddress | FT -AutoSize
PING
Description: Checks connectivity to a specific host. Commonly used to check for liveliness, but also used to measure network latency.
PowerShell: Test-NetConnection
Sample command lines:
Test-NetConnection www.microsoft.com
Test-NetConnection -ComputerName www.microsoft.com -InformationLevel Detailed
Test-NetConnection -ComputerName www.microsoft.com | Select -ExpandProperty PingReplyDetails | FT Address, Status, RoundTripTime
1..10 | % { Test-NetConnection -ComputerName www.microsoft.com -RemotePort 80 } | FT -AutoSize
NSLOOKUP
Description: Name server lookup. Mostly used to find the IP address for a given DNS name (or vice-versa). Has many, many options.
PowerShell: Resolve-DnsName
Sample command lines:
Resolve-DnsName www.microsoft.com
Resolve-DnsName microsoft.com -type SOA
Resolve-DnsName microsoft.com -Server 8.8.8.8 –Type A
route print
Description: The Get-NetRoute cmdlet gets IP route information from the IP routing table, including destination network prefixes, next hop IP addresses, and route metrics. Run this cmdlet without any parameters to get all IP routes from the routing table.
PowerShell: Get-NetRoute
Sample command lines:
Get-NetRoute | Format-List -Property *
Get-NetRoute -AddressFamily IPv6
Get-NetRoute -InterfaceIndex 12
Get-NetRoute -DestinationPrefix "0.0.0.0/0" | Select-Object -ExpandProperty "NextHop"
Get-NetRoute | Where-Object -FilterScript { $_.NextHop -Ne "::" } | Where-Object -FilterScript { $_.NextHop -Ne "0.0.0.0" } | Where-Object -FilterScript { ($_.NextHop.SubString(0,6) -Ne "fe80::") }
Get-NetRoute | Where-Object -FilterScript {$_.NextHop -Ne "::"} | Where-Object -FilterScript { $_.NextHop -Ne "0.0.0.0" } | Where-Object -FilterScript { ($_.NextHop.SubString(0,6) -Ne "fe80::") } | Get-NetAdapter
Get-NetRoute | Where-Object -FilterScript { $_.ValidLifetime -Eq ([TimeSpan]::MaxValue) }