Check free IPs in a subnet

We can use Test-Connection cmdlet here, it sends ICMP echo request packets (“pings”) to the list of IP address you define. Then we just need to loop through the entire range using first three IP octet as prefix and writing desired output.

1..254  | ForEach-Object {
if(!(Test-Connection 10.219.111.$_ -count 1 -Quiet)) {
Write-Output "10.219.111.$_ is available"
else {
Write-Output "10.219.111.$_ is in use"

Be the first to comment

Leave a Reply

Your email address will not be published.