locked
Query all DNS servers in a domain for a matching A record RRS feed

  • Question

  • Hello

    I've recently been reading this http://blogs.technet.com/b/heyscriptingguy/archive/2009/02/23/how-do-i-check-host-name-records.aspx

    What I am looking to do is to query all of our dns servers in the domain to see if a specific a record or cname exists

    Its basically to see where DNS replication is at. I know from Trial and error that it takes a few hours for a DNS created on server A to replicate to the rest of the servers in our domain

    Its nothing urgent, its more to satifsfy my own curiosity

    • Moved by Bill_Stewart Monday, October 20, 2014 5:40 PM This is not "scripts on demand"
    Tuesday, September 9, 2014 7:29 AM

Answers

  • Here is a bit of a hint:

    $wmiprops=@{
        Class='MicrosoftDNS_AType'
        NameSpace='root\MicrosoftDNS'
        Filter="DomainName='contoso.com' AND IPAddress='192.168.1.1'"
        ComputerName=<dns servername>
    }
    
    Get-WmiObject @wmiprops
    
    Using a "splat" makes it easier to read and edit.


    ¯\_(ツ)_/¯


    • Edited by jrv Wednesday, September 10, 2014 11:05 AM
    • Proposed as answer by jrv Tuesday, September 23, 2014 10:29 AM
    • Marked as answer by Just Karl Tuesday, June 2, 2015 10:33 PM
    Wednesday, September 10, 2014 11:04 AM

All replies

  • Start by using this as an excuse to learn scripting.  You can do that here:http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx


    ¯\_(ツ)_/¯

    Tuesday, September 9, 2014 11:27 AM
  • I have a fair knowledge and understanding of scripting - however its that I've gotten stuck

    I've tried to modify an existing script with what I'm trying to do - rather than trying to reinvent the wheel

    Code I'm trying is as follows:

    Function Get-DnsServer
    {
     Begin {Write-Host -ForeGroundColor Cyan "Obtaining local DNS Server information..."}
     Process {
      (Get-WmiObject -Class `
    win32_networkadapterconfiguration -filter "ipenabled =   $true").DnsServerSearchOrder[0]
     } #end Process
    } #end Get-DnsServer

    Function Get-DomainName
    {
     Begin {Write-Host -ForeGroundColor DarkCyan "Obtaining local DNS Domain information..."}
     Process {
      (Get-WmiObject -Class win32_networkadapterconfiguration -filter "ipenabled =   $true").DnsDomain
     } #end Process
    } #end Get-DnsServer

    Function Get-ARecords($DnsServer)
    {
     Begin { Write-Host -ForeGroundColor Yellow "Connecting to $DnsServer ..." }
     Process { Write-Host -ForeGroundColor Green "Retrieving A records ..."
     

    Get-WmiObject -Class MicrosoftDNS_AType -NameSpace Root\MicrosoftDNS -ComputerName $DnsServer  -Filter "DomainName = 'contoso.com'" |
      Select-Object -property Ownername, ipaddress | ? { $_.ipaddress -like '192.168.1.1' } | sort ownername

     } #end process
    } #end Get-ARecords

    # *** Entry Point to Script ***

    $DnsServer = Get-DnsServer
    $DnsDomain = Get-DomainName
    Get-ARecords -DnsDomain $DnsDomain -DnsServer $DnsServer

    What I am trying to do:

    Unmodified, the code is as follows:

      Get-WmiObject -Class MicrosoftDNS_AType -NameSpace Root\MicrosoftDNS -ComputerName $DnsServer  -Filter "DomainName = 'contsoso.com'
    Select-Object -property Ownername, ipaddress

    When this runs, it returns all A records for the domain. I dont want this, I only want to see the A records that match 192.168.1.1

    When I run the modified code, it doesnt return the A record matching 192.168.1.1; it instead tries to contact the DNS server at 192.168.1.1 to run the query

    From what I've read (unless I've read it wrong) the above query should work - but doesnt appear to. Thats where I'm stuck

    Any assistance, or a point in the right direction would be appreciated

    Wednesday, September 10, 2014 5:32 AM
  • Start by reading the instructions on the box - so to speak.

    HELP Get-WmiObject  -full

    Think about what the "computername" argument is used for.  What does "Filter" do.

    The most important thing a Tech needs to learn to do is to read the instructions.  A technician is a person who knows how to read and  understand technical information.  Remember you are looking for an address and NOT a domain.  THis is a fundamental concept to learn in all of scripting and computer technology.


    ¯\_(ツ)_/¯

    Wednesday, September 10, 2014 10:53 AM
  • Here is a bit of a hint:

    $wmiprops=@{
        Class='MicrosoftDNS_AType'
        NameSpace='root\MicrosoftDNS'
        Filter="DomainName='contoso.com' AND IPAddress='192.168.1.1'"
        ComputerName=<dns servername>
    }
    
    Get-WmiObject @wmiprops
    
    Using a "splat" makes it easier to read and edit.


    ¯\_(ツ)_/¯


    • Edited by jrv Wednesday, September 10, 2014 11:05 AM
    • Proposed as answer by jrv Tuesday, September 23, 2014 10:29 AM
    • Marked as answer by Just Karl Tuesday, June 2, 2015 10:33 PM
    Wednesday, September 10, 2014 11:04 AM
  • Thanks, but I couldnt figure it out

    I've managed to do what I was trying to acheive with Dnslint

    Tuesday, September 23, 2014 7:06 AM
  • So your curiosity got bored.  I guess scripting is not for you.


    ¯\_(ツ)_/¯

    Tuesday, September 23, 2014 10:29 AM