Share via

Configure SecureSecondaries via powershell cmdlet from variable

Wes 0 Reputation points
2023-02-14T02:41:18.2733333+00:00

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.

Community Center | Not monitored
0 comments No comments

1 answer

Sort by: Most helpful
  1. Limitless Technology 45,231 Reputation points
    2023-02-14T16:10:40.05+00:00

    Hi. Thank you for your question and reaching out. I’d be more than happy to help you with your query

    To configure SecureSecondaries via PowerShell cmdlet from a variable, you can use the following steps:

    1. Define a variable containing the list of IP addresses of the secure secondary servers:

    $SecureSecondaries = "10.0.0.1","10.0.0.2","10.0.0.3"

    1. Use the Set-DnsServerZone cmdlet to configure the secure secondary servers for the zone:

    Set-DnsServerZone -Name "example.com" -SecureSecondaries $SecureSecondaries

    This cmdlet sets the SecureSecondaries property for the specified DNS zone. In this example, the zone name is "example.com" and the value of the $SecureSecondaries variable is passed to the SecureSecondaries parameter.

    By executing this cmdlet, the secure secondary servers will be configured for the specified DNS zone.

    In addition, If the Set-DnsServerPrimaryZone cmdlet is not accepting the value as a variable or from a CSV file, you can try converting the comma-separated string of IP addresses into an array of strings using the -split operator in PowerShell. Here's an example:

    Example comma-separated string of IP addresses

    $secureSecondaries = "192.168.1.2,192.168.1.3,192.168.2.2"

    Convert the string into an array of strings using -split

    $secureSecondariesArray = $secureSecondaries -split ","

    Set the secure secondaries using the array

    Set-DnsServerPrimaryZone -Name "example.com" -SecureSecondaries $secureSecondariesArray

    You can do the same for the NotifyServers parameter. Hope this helps!

    If the reply was helpful, please don’t forget to upvote or accept as answer, thank you.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.