PowerShell for Windows Admins

May 21 2011   3:01AM GMT

Testing network connectivity

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

One of the standard troubleshooting tasks when investigating a problem is deciding if the machine can communicate on the network. The approach is usually

  • ping the loop back address to check TCP/IP is working
  • ping the machines own address
  • ping the default gateway
  • ping other servers

This means running ipconfig to discover some of the information and  then running pings

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
function test-networkconnectivity {
[CmdletBinding()]
param()

$nic = Get-WmiObject Win32_NetworkAdapterConfiguration `
-Filter "DHCPEnabled = $true AND IPEnabled = $true"

Write-Verbose "TCP/IP Stack"
Test-Connection -ComputerName 127.0.0.1

Write-Verbose "Local Address"
Test-Connection -ComputerName $nic.IPAddress[0]

Write-Verbose "Default Gateway"
Test-Connection -ComputerName $nic.DefaultIPGateway

Write-Verbose "DNS Server"
foreach ($address in $nic.DNSServerSearchOrder){
Test-Connection -ComputerName $address}

}

 

We can simplify this action.  Use WMI to get the data (I’m assuming we are doing this on a client) from the DHCP enabled NIC. I added the filter for IPEnabled to filter out BlueTooth adapters.

We can then use Test-Connection to perform the pings.  The various results are labelled accordingly if we use the –verbose switch

test-networkconnectivity -Verbose

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: