I am trying to come up with a script that will validate ($True or $False) if a specified list of DNS Zone Names and their associated Master Servers list exists on a DNS Server.
Example List:
Zone Names Master Servers testCorp.com "158.192.20.251","155.108.26.130","156.107.74.100","157.191.169.71","156.109.176.244" 190.157.in-addr.arpa "157.191.169.71","156.109.176.244" testCorpacademy.com "157.191.169.71","156.109.176.244","156.107.74.71" solutions.testCorp.com "209.244.0.3" amazon.cz "8.8.8.8"
I can run
gwmi -Namespace root\MicrosoftDNS -Class MicrosoftDNS_Zone -Filter "ZoneType = 4" | Select Name,{$_.MasterServers}
This gets me the zones and master servers from the server.
What I need is to do is:
1)Confirm if the DNS Zone in the list exists on the server
2)If the DNS Zone exists verify that all the Master Servers are specified (the Zone can contain other master servers but must have the ones specified)
3)Repeat this for each DNS Zone
4)Validate $True if all DNS Zones exist and have the specified Master Servers
5)Validate $False if any of the Zones or associated Master Servers are not present on the server.
I started trying to flush this out and have come up with this so far:
$ZonesExist = $False ### Index in to DNSZones array for the region. $ZoneName = $NewDNSZone[0] $MasterServer1 = $NewDNSZone[1] $MasterServer2 = $NewDNSZone[2] $MasterServer3 = $NewDNSZone[3] $MasterServer4 = $NewDNSZone[4] $MasterServer5 = $NewDNSZone[5] ### This section checks for Conditional Forwarders for the core Zones. These entries are required! # Create an array of regional DNS Zones $NewDNSZones = @() $NewDNSZones = ,("testCorp.com","158.192.20.251","155.108.26.130","156.107.74.100","157.191.169.71","156.109.176.244") $NewDNSZones += ,("190.157.in-addr.arpa","157.191.169.71","156.109.176.244") $NewDNSZones += ,("testCorpacademy.com","157.191.169.71","156.109.176.244","156.107.74.71") $NewDNSZones += ,("solutions.testCorp.com","209.245.0.3") $NewDNSZones += ,("amazon.cn","8.8.8.8") $ExistingZones = gwmi -Namespace root\MicrosoftDNS -Class MicrosoftDNS_Zone -Filter "ZoneType = 4" | Select Name,{$_.MasterServers} ForEach ($Zone in $ZoneName) { if ($Zone -like $ExistingZones.Name} { if ($MasterServer1 -eq $ExistingZones.MasterServers) } }
I am having some trouble figuring out how to first validate the DNS Zone name, then if that is there validate that that DNS Zone has the proper Master Servers and cycling through all the DNS Zone names.
Any help and guidance is appreciated.
~Ed