June 4, 2009

Ping servers using powershell

A simple check to see if your server is still alive and a poor admins script that can be run as a service:
#create a file that has IP's or ServerNames to check, one per line.
$file=gc "D:\HearbeatPing.txt"

foreach($ip in $file)
{
$OK=get-wmiobject win32_pingstatus -Filter "Address='$ip'" | Select-Object statuscode

if($OK.statuscode -eq 0) {
write-host $ip is UP}
else {
write-host $ip is DOWN -background "red"}
}

No comments:

Post a Comment