Powershell : Scripting Conditional Forwarder Zones for Privatelink Zones

This article is a follow on from the post here

When you end up using these conditional forwarder zones that need to be non-Active directly replicated on all your none Entra based Domain Controllers, if you have a lot of zones to add sometimes a script works better than the manual effort and will be more consistent.

First we need to define the local domain controllers with $domainControllers this is where the zone will be created, then you need a location of the zones.txt file and then finally a list of servers to use as forwarders, so lets get scripting:

Note : The zones.txt file will contain a list of the domain name, you will need to ensure you have one domain per line with no spaces at the end of the domain name

# Define the list of domain controllers
$domainControllers = @("beardc1", "beardc2", "beardc3", "beardc4")

# Define the path to the zones file and the master servers
$zoneFilePath = "zones.txt"
$masterServers = @("10.70.335.22", "10.84.337.44")

# Read the zone names from the file
$zones = Get-Content -Path $zoneFilePath

# Loop through each domain controller and each zone name, then execute the command with verbose output

foreach ($dc in $domainControllers) {
    foreach ($zone in $zones) {
        Write-Output "Adding zone '$zone' on domain controller '$dc'..."
        Add-DnsServerConditionalForwarderZone -Name $zone -ComputerName $dc -MasterServers $masterServers -PassThru -Verbose
        Write-Output "Zone '$zone' added to domain controller '$dc'."
    }
}

Previous Post Next Post

نموذج الاتصال