Thursday, December 22, 2011

(Powershell Script) Ping list of IPs or hostnames

My first script :-

Below script uses WMI's Win32_PingStatus under the hood. It returns, by default, four "result" objects, each of which contains various properties, including a StatusCode, which will be 0 for successful pings Statuscode binary value of 11010 means that ping failed 

Copy below code and create .PS1 extension file
*************************************************************************
 # create a file with name "ips.txt" (containing ips and hostnames) put it under folder “c:\host”
$list = get-content "ips.txt"
foreach ($ip in $list)
{$result = Get-WmiObject Win32_PingStatus -filter "address='$IP'"
if ($result.statuscode -eq 0)
{
write-host "$IP Server is up"
}
else
{
Write-host "$IP Server is down"
}
}
*************************************************************************
Powershell Ping multiple IP addresses
Capture ping Latency or drops results with powershell - Part1
Capture multiple IP Latency or drops results with powershell Test-Connection - Part 2
Schedule PowerShell (.PS1 file) script in Windows Task Scheduler - Part 3

No comments: