Ping a subnet
I recently needed to find which IP addresses were active on a subnet to track down a printer. Quickest way was to ping them.
function ping-subnet {
param (
[parameter(Mandatory=$true)]
[ValidatePattern("\b\d{1,3}\.\d{1,3}\.\d{1,3}\b")]
[string]$subnet
)
0..255 | foreach {
$address = "$subnet.$_"
if (Test-Connection -ComputerName $address -Count 1 -Quiet){
Test-Connection -ComputerName $address -Count 1
}
}
}
Put the subnet in as a parameter. Then work through 0 – 255 building an address from the subnet. use test-connection in quiet mode and if it responds do a 1 count test-connection (ping) to get the result.
Not necessarily the quickest but it was quick to throw together and it works