DNS Lookup

Everything I’ve read online about this topic always contains how to look up multiple IP’s from a single name server. I’m looking to do the opposite to test conditional forwarders on multiple domain controllers. The script I have tests the URL against an array of domain controllers, and it works. I’m trying to figure out how I can output which DC failed to resolve when it errors. Any suggestions?

$URL = "URL"
$NameServers = @("Domain Controller 1", "Domain Controller 2", "Domain Controller 3", "Domain Controller 4")

foreach ($NameServer in $NameServers){

Resolve-DnsName -Name $URL -Server $NameServer


Architect tip: make your life easier and make all dc’s gc’s and all gc’s dns servers.

$dcs = (Get-ADDomainController -Filter * | select -first 3).name
$url = ‘www.powershell.org

foreach ($dc in $dcs){if(!(Resolve-DnsName $url -Server $dc)){“$dc failed to resolve $url”}}

Fyi… $NameServers = “Domain Controller 1”, “Domain Controller 2”, “Domain Controller 3”, “Domain Controller 4” is just as good as @()

throw an error action in there.

Resolve-DnsName $url -Server $dc -ea silentlycontinue