PowerShell – Simple Ping Script (Server is up or Server is Down)
NOTE: You’ll need to be in the c:\host directory when you run this script.
# create a file with name "ips.txt" (containing ips and/or 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" } } $collection | Export-Csv -c:\host\PingResults2 .\ServerStatus.csv -NoTypeInformation
Example Output