DNS Lookup

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Dan Potter Dan Potter 3 months, 2 weeks ago.

  • Author
    Posts
  • #51955
    Profile photo of Mike Catalano
    Mike Catalano
    Participant

    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?

    clear
    $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
    
    }
    
  • #51961
    Profile photo of Dan Potter
    Dan Potter
    Participant

    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 @()

  • #51963
    Profile photo of Dan Potter
    Dan Potter
    Participant

    throw an error action in there.

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

You must be logged in to reply to this topic.