Validate DNS Zone Names and Master Servers

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				"","","","",""			"",""			"","",""			""				""

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   = ,("","","","","","")
		$NewDNSZones  += ,("","","")
		$NewDNSZones  += ,("","","","")
		$NewDNSZones  += ,("","")
		$NewDNSZones  += ,("","")

	$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.


Are these Windows DNS servers?


So, not knowing what tools you’re able to use, have you dug into either the DNS Server commands in the RSAT, or into the WMI classes exposed by DNS Server?

I have looked at the WMI classes and the following command gets me the info I need (sort of):

gwmi -Namespace root\MicrosoftDNS -Class MicrosoftDNS_Zone -Filter "ZoneType = 4" | Select Name,{$_.MasterServers}

This gives me the name of any ConditionalForwarderZones and the associated MasterServers like so:

Name MasterServers {,} {,} {,} {,}
dev-int.mso.local {,} {,,} {,} {,,,…} {,,} {} {,} {} {} {,}

My problem here is even though I think I am calling to have the string values expanded with the {$.MasterServers} they are not fully expanded. I think it is recognizing {$.MasterServers} as I get the same results whether I use that or simply ‘MasterServers’.

Once I get that worked out I then need to figure out the programming logic so that I can ensure that all the zones and their associated Master Servers match the list.

No, that syntax isn’t expanding them. You can’t really get two properties and expand one; you have to create our own objects. For example:

gwmi -Namespace root\MicrosoftDNS -Class MicrosoftDNS_Zone -Filter "ZoneType = 4" |
foreach {
  foreach ($server in $_.masterservers) {
    new-object -type psobject -prop @{Name=$_.Name;MasterServer=$server}

That’ll give you one output object per master server IP address. Or roughly should - you may need to tweak and adjust to get exactly what you need.

Thanks Don, this helps a lot.