PowerShell | Network Connection Testing 

We have a network connection error. But where in the line? is it the computer, switch, gateway, dns?

I made this quick script to start at the local computer and test outwards to see where the break in the chain is and when it does fail it brings up IPConfig /all to review your settings. I have thought about spending a couple extra mins to make this into a function. Msg me in the comments or email me and ill update it to be a funtion “Get-NetworkConnectionTest”

<#

.SYNOPSIS

Test the IP and DNS connections. Starting at own system then moving outwards

.DESCRIPTION

.EXAMPLE

.NOTES

Author. Luke Keam

Company Name. techgeek.biz

Published. on 1/1/2017 AUS

Version. 1

Copyright. Free for personal and commercial use. As long as reference kept.
Questions, comments, suggestions always welcome. Please email me.

Maybe verison 2 to be a function?
.LINK

Website. techgeek.biz

Email. [email protected]

#>

# Test LocalHost IP

Try {

Test-Connection 127.0.0.1 -ErrorAction Stop

Test-Connection ::1 -ErrorAction Stop

}

Catch {

ipconfig /all

Write-Host “
Test LocalHost IP Failed!!!!

Review IpConfig /all Settings Above”

}

# Test Localhost DNS

Try {

Test-Connection localhost -ErrorAction Stop

}

Catch {

ipconfig /all

Write-Host “
Test Localhost DNS Failed!!!!

Review IpConfig /all Settings Above”

}

# Test DefaultGateway Credit to DWSR from powershell.slack.com for this one

Try {

Get-NetIPConfiguration | select -ExpandProperty ipv4defaultgateway | select -ExpandProperty nexthop | %{ Test-Connection $_ -ErrorAction Stop }

}

Catch {

ipconfig /all

Write-Host “
Test DefaultGateway IP Failed!!!!

Review IpConfig /all Settings Above”

}
# Test Google and OpenDNS IP

Try {

Test-Connection 8.8.8.8 -ErrorAction Stop

Test-Connection 208.67.222.222 -ErrorAction Stop

}

Catch {

ipconfig /all

Write-Host “
Test Google and OpenDNS IP Failed!!!!

Review IpConfig /all Settings Above”

}

# Test Google DNS and OpenDNS DNS

Try {

Test-Connection google.com -ErrorAction Stop

Test-Connection opendns.com -ErrorAction Stop

}

Catch {

ipconfig /all

Write-Host “
Test Google DNS and OpenDNS DNS Failed!!!!

Review IpConfig /all Settings Above”

}

Hope this was helpful 


Luke Keam
Thank you for reading. Email me: [email protected]
Luke Keam | techgeek.biz