Get Conditional Forwarders with IP addresses - Creating Multiple Conditional Forwarders from csv-txt file

The below PS script exports the conditional forwarders and their master server ip addresses

gwmi -Namespace root\MicrosoftDNS -Class MicrosoftDNS_Zone -Filter "ZoneType = 4" |
Select -Property @{n='Name';e={$_.ContainerName}}, @{n='DsIntegrated';e={$_.DsIntegrated}}, @{n='MasterServers';e={([string]::Join(',', $_.MasterServers))}}, @{n='AllowUpdate';e={$_.AllowUpdate}} | Export-Csv "condForwarders.csv"


The below command reads a txt file for the conditional forwarder names and for each name it creates a AD integrated conditional forwarder. The master server ip can be read from txt or hardcoded lke I do in this example.

Import-Csv "c:\arecords.txt" |
foreach{Add-DnsServerConditionalForwarderZone -Name $ -ReplicationScope "Forest" -MasterServers}


arecords.txt content can be something like this: