Skip to content

Instantly share code, notes, and snippets.

@anroots
Created March 7, 2014 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anroots/9421460 to your computer and use it in GitHub Desktop.
Save anroots/9421460 to your computer and use it in GitHub Desktop.
A PowerShell script that pings a list of static IP-s to determine the UP / DOWN status of each IP
# A PowerShell script to check the status (online / offline) of NODE-s
# Pings each NODE with a ICMP packet to get its status
#
# Author Ando Roots <ando@sqroot.eu> 2014-03-05
# -------------- CONFIG ------------------- #
# Node numbers to ping
$NodeList = 11,12,13,14,15,16,17,18,24
# How many pings to each node. The status is DOWN if any of them fail.
$PingCount = 2
# Time to Live for the ping packets
$TTL = 5
# ------------ END CONFIG ----------------- #
echo ""
date
echo "NODE status check started"
echo ""
$Percent = 10
$SuccessCounter = 0
foreach ($Node in $NodeList) {
# Full NODE IP to ping (CISCO gateway)
$IP = "10.54."+$Node+".62"
# Progress window
write-progress -activity "Testing NODE Links..." -status "$Percent% complete" -percentcomplete $Percent -currentOperation "connecting to N$Node..."
# Ping NODE, save output (bool) to a var
$IsOnline = test-connection ($IP) -count $PingCount -Quiet -TimeToLive $TTL
if ($IsOnline) {
echo "N$Node is UP"
$SuccessCounter += 1
} else {
echo "N$Node is DOWN!"
}
$Percent += 10
}
echo "-----------------"
# Show summary
$NodeCount = $NodeList.length
$UPPercent = $SuccessCounter*100/$NodeList.length
echo "$SuccessCounter of $NodeCount UP ($UPPercent%)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment