I am in the process of writing some scripts to automate DR recovery of a physical STANDALONE Windows DNS server environment that consists of 1 Master and 4 slaves (the Master and 2 slaves are Win2k19, the other 2 slaves are currently Win2k12R2. All scripting is being coded/run from the Win2k19 servers).
Note - These are NOT AD Integrated DNS servers. We have no plans to migrate the zones into AD DNS nor is any of this environment in the cloud.
I have exported via Powershell the Zone configuration on the Master DNS Server to XML file as a backup file, and on a refreshly built Win2k19 server that currently is not hosting any zones I am attempting to import the zone configurations to simulate a complete environment failure/rebuild via use of Powershell scripts and the XML backup file.
At the moment, the part of the script I am dealing with is trying to import and apply the Secure Secondaries & Notify Servers lists from the Master server's XML backup file. The zone transfer lists do not just incorporate my primary group of DNS servers (which actually host our internal root zones) but also additional DNS servers in the company where we replicate certain zones to as well.
The Powershell cmdlet Set-DnsServerPrimaryZone is what is used to set the Secure Secondaries and Notify Servers, but it appears to only accept bare text, it will not accept the value as a variable, even if that variable is a string of comma separated IP addresses (the bare text can be a list of comma separated IPs).
I have also attempted the original export to CSV and then importing that, but that also is not accepted by the cmdlet
Example commands that DO work:
Set-DnsServerPrimaryZone -Name example.dns -Notify notify -NotifyServers 192.168.0.1,192.168.0.2,192.168.0.3 -SecureSecondaries transfertozonenameserver -SecondaryServers 192.168.0.1,192.168.0.2,192.168.0.3
Set-DnsServerPrimaryZone -Name example.dns -Notify $zone.notify -NotifyServers 192.168.0.1,192.168.0.2,192.168.0.3 -SecureSecondaries $zone.securesecondaries -SecondaryServers 192.168.0.1,192.168.0.2,192.168.0.3
Example commands that do NOT work, where the input variable for Notify Servers and Secondary Servers is an array of IP addresses even if it contains a single IP only (contents of XML file were imported to a variable called "$zone", refer further below for example source XML data)
Set-DnsServerPrimaryZone -Name $zone.zonename -Notify $zone.notify -NotifyServers $zone.notifyservers -SecureSecondaries $zone.securesecondaries -SecondaryServers $zone.secondaryservers
Set-DnsServerPrimaryZone -Name $zone.zonename -Notify $zone.notify -NotifyServers $zone.notifyservers[0],$zone.notifyservers[1],$zone.notifyservers[2] -SecureSecondaries $zone.securesecondaries -SecondaryServers $zone.secondaryservers[0],$zone.secondaryservers[1],$zone.secondaryservers[2]
$Secondaries = $zone.secondaryservers[0] + "," + $zone.secondaryservers[1] + "," + $zone.secondaryservers[2]
$notifyservers = $zone.notifyservers[0] + "," + $zone.notifyservers[1] + "," + $zone.notifyservers[2]
Set-DnsServerPrimaryZone -Name $zone.zonename -Notify $zone.notify -NotifyServers $notifyservers -SecureSecondaries $zone.securesecondaries -SecondaryServers $Secondaries
[string]$Secondaries = $zone.secondaryservers[0] + "," + $zone.secondaryservers[1] + "," + $zone.secondaryservers[2]
[string]$notifyservers = $zone.notifyservers[0] + "," + $zone.notifyservers[1] + "," + $zone.notifyservers[2]
Set-DnsServerPrimaryZone -Name $zone.zonename -Notify $zone.notify -NotifyServers $notifyservers -SecureSecondaries $zone.securesecondaries -SecondaryServers $Secondaries
Example content of the XML file that has been imported as the variable "$zone" (note that I have culled some fields out in this example XML as they are not important for what I am trying to do)
Example error generated from Powershell when using a variable to insert the NotifyServers and SecondaryServers values
Cannot process argument transformation on parameter 'NotifyServers'. Cannot convert the value "192.168.0.1,192.168.0.2,192.168.0.3" to type "System.Net.IPAddress[]", Error : "Cannot convert value "192.168.0.1,192.168.0.2,192.168.0.3" to type "System.Net.IPAddress[]". Error: "An invalid IP Address was specified"
As I am dealing with hundreds of internal DNS zones, which actually have different zone transfers setup, I cannot just do a copy/paste of the notify and secondary server IPs to apply for all zone transfers, but need to import and configure unique transfer settings on each zone.
Recommendations on how to have Powershell accept the Notify & Secondary Server lists via a variable would be appreciated.