Validate IP Entry in DNS

I’m having a hard time checking to see if an IP exists in DNS. (not that a server is up, just that the IP exists)

So the short of it is to import a csv file that contains a header for “Zone” and “IP”, check DNS if a HOST A Record Exists (by IP); if it does, do nothing, if it doesnt create it

Seems simple in my head but im getting lost on how to manipulate the objects from the initial get-dnsserverresourcerecord query

$DNSCheck = import-csv -path C:\test.csv
foreach ($row in $DNSCheck)
$GetDNSEntry = $null
$GetDNSEntry = get-dnsserverreourcerecord -zonename $row.Zone -RRType "A" | select-object RecordData -expand-Property RecordData
If ($getDNSEntry -match $row.IP)
 add-dnsresourcerecordA -Name "." -zoneName $ -ipv4address $row.IP

i dont have a problem doing this for the zone check and creation

$checkzone = $null
$checkzone = (get-dnsserverzone -name $
if($checkzone -ne $null)
 {Write-host " $($row.Zone) DNS Zone Already Exists"
 {Write-Host "creating zone $($row.URL); Add-dnsserverprimaryzone -name $ -replicationscope Domain}

Any pointers would be appreciated!

I’m not completely sure what you mean with “to manipulate the objects from the initial get-dnsserverresourcerecord query” but the following might be helpful. With this snippet you get a complete list of all A records from all zones existing on the server.

$AllZonesAllARecords = Get-DnsServerZone |
ForEach-Object {
$Zone = $.ZoneName
Get-DnsServerResourceRecord -RRType A -ZoneName $
.ZoneName |
Select-Object -Property HostName,
@{Name = ‘IP’; Expression = {$_.RecordData.IPv4Address}},
@{Name = ‘Zone’; Expression = {$Zone}}
Now you could use Compare-Object to compare this list to your scv file and use the output accordingly.


Thanks for the response. I’m just having a hard time getting the data I need and then comparing, to see if it exists. I have a File with Zone Names and IP’s. I figured out how to check the existing zones and create a new one if it hasnt been created. I then want to go further and check if an IP has been created in a zone.

So i have a zone with IP’s that should be associated with it of and
If the zones not there i create it. If it is created then i want to check if the IP’s have been created under that zone, and if they havent, create them.

Sorry if i’m not conveying the question clearly, its frustrating because i can get the data in some form or fashion but I am having a hard time using it properly.

Did you try the code I posted? You can use Compare-Object to get the difference between your csv file and the created list of DNS records. Then you use this “list of differences” to create the DNS zones and the DNS records you need.

I did, and I appreciate the pointers. I went about it a little different but you got me where i needed to be.

Thanks again!