Simple Ping Script in PowerShell for block of IPs

Here is a simple ping script for block of IPs.

 

Bring PowerSheel ISE and copy & paste below script.

 

$ping = New-Object System.Net.NetworkInformation.Ping
$IPNet = "192.168.100";

$IPNode = 1;

while ( $IPNode -le 254 )

{
 $IPTarget = "$IPNet.$IPNode";
 $stat = $ping.send($IPTarget)  select status;
 $result = "$IPTarget $stat";
 $result;
 $IPNode = $IPNode + 1;
}

 

Output would be like…

192.168.100.1 @{Status=Success}
192.168.100.2 @{Status=TimedOut}
192.168.100.3 @{Status=Success}
192.168.100.4 @{Status=Success}
192.168.100.5 @{Status=Success}
192.168.100.6 @{Status=Success}

:

:

 

 

Or using "Test-Connection commands

 

$IPNode = 1;

while ( $IPNode -le 254 )
{
 If (Test-Connection 192.168.100.$IPNode -Count 1 -Quiet)
{
 "192.168.100.{0} : UP" -f $IPNode;
}
 Else
{
 "192.168.100.{0} : DOWN" -f $IPNode;
}

 $IPNode = $IPNode + 1;
 
}

 

Output would be like…

192.168.100.1 : UP
192.168.100.2 : DOWN
192.168.100.3 : UP
192.168.100.4 : UP
192.168.100.5 : UP

:

:

 

 

 

 

Leave a Reply