DNS Lookup

Welcome Forums General PowerShell Q&A DNS Lookup

Viewing 2 reply threads
  • Author
    Posts
    • #51955
      Participant
      Topics: 4
      Replies: 4
      Points: 0
      Rank: Member

      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
      Participant
      Topics: 18
      Replies: 573
      Points: 32
      Rank: Member

      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
      Participant
      Topics: 18
      Replies: 573
      Points: 32
      Rank: Member

      throw an error action in there.

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

Viewing 2 reply threads
  • The topic ‘DNS Lookup’ is closed to new replies.