This PowerShell script will take a routers IP address (or any other IP address for that matter) from an input box and use the Win32_PingStatus class to verify if the router is on line or off line by reading the StatusCode value where 0 signifies a successful ping code. If the router is on line the Results Set is written in green and if it is not on line it is written in red.
This script can be used at the office by using the Prompted PS1 Script or at home if you have a wireless router using the Specified PS1 Script to be used when you suspect that your router is down by hard coding your Routers IP address.
Note: For a complete list of the available Status Codes for Windows scripting technologies see the chart at the end of this post.
$strIpAddress = Read-Host "Enter IP Address"
Clear
$QueryString = ('Select StatusCode From Win32_PingStatus Where Address = "' + $strIpAddress + '"')
$ResultsSet = Gwmi -Q "$QueryString"
If ($ResultsSet.StatusCode -Eq 0)
{Write-Host -Fore Green "The Router Is On Line"}
Else {Write-Host -Fore Red "The Router Is Off Line"}
# Router IP Address
$strIpAddress ="192.168.1.1"
PingStatus StatusCode Codes
Code
Description
0
Success
11001
Buffer Too Small
11002
Destination Net Unreachable
11003
Destination Host Unreachable
11004
Destination Protocol Unreachable
11005
Destination Port Unreachable
11006
No Resources
11007
Bad Option
11008
Hardware Error
11009
Packet Too Big
11010
Request Timed Out
11011
Bad Request
11012
Bad Route
11013
TimeToLive Expired Transit
11014
TimeToLive Expired Reassembly
11015
Parameter Problem
11016
Source Quench
11017
Option Too Big
11018
Bad Destination
11032
Negotiating IPSEC
11050
General Failure
No Comments