Help with an automated DNS listing output

Here’s the code so far. I want to scan the network using Test-Connection and find all responsive IP addresses, thus building a comprehensive DNS listing in real time that would either be stored on a file share or sent via email, or both. Can anyone help me rework this so that it builds two arrays – one with the taken IPs & hostname in two columns, and one with the free IPs.

$range = 1..254 foreach ($IP in $range) { if ((Test-Connection -ComputerName "192.168.254.$IP" -Count 1).IPV4Address -ne $NULL) { $dnsHostName = ([System.Net.Dns]::GetHostbyAddress("192.168.254.$IP")).HostName $takenIPs = New-Object PSObject $takenIPs | Add-Member -MemberType NoteProperty -Name IPv4 -Value "192.168.254.$IP" -PassThru $takenIPs | Add-Member -MemberType NoteProperty -Name HostName -Value "$dnsHostName" -PassThru } if ((Test-Connection -ComputerName "192.168.254.$IP" -Count 1).IPV4Address -eq $NULL) { $freeIPs = New-Object PSObject $freeIPs | Add-Member -MemberType NoteProperty -Name IPv4 -Value "192.168.254.$IP" -PassThru } } 

submitted by /u/Marquis77
[link] [comments]

Leave a Reply