Here is a simple Ping script with list of IP address or computer names.
1. IPList.txt
Format of "IPList.text" would be like below.
192.168.100.1
192.168.100.2
192.168.100.3
192.168.100.4
192.168.100.5
2. Script example #1
$IPNodes = Get-Content "C:\temp\IPList.txt"
foreach ($IP in $IPNodes)
{
if (Test-Connection -IPAddress $IP -Count 1 -ErrorAction SilentlyContinue)
{
Write-Host "$IP is UP" -ForegroundColor Blue;
}
Else
{
Write-Host "$IP is Down" -ForegroundColor Red;
}
}
Output would be……
192.168.100.1 is UP
192.168.100.2 is DOWN
192.168.100.3 is UP
192.168.100.4 is UP
192.168.100.5 is UP
3. Script example #2
$IPNodes = Get-Content "C:\temp\IPList.txt"
foreach ($IP in $IPNodes)
{
if (Test-Connection -IPAddress $IP -Count 1 -Quiet)
{
"$IP is UP";
}
Else
{
"$IP is Down";
}
}
Output would be……
192.168.100.1 is UP
192.168.100.2 is DOWN
192.168.100.3 is UP
192.168.100.4 is UP
192.168.100.5 is UP