Get-WmiObject to get Specific DNS records

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Richard Siddaway Richard Siddaway 1 month, 4 weeks ago.

  • Author
    Posts
  • #62853
    Profile photo of Dave
    Dave
    Participant

    Hi all,

    I'm trying to get a list of static DNS A Records. I've tried doing a double filter, adding a Where-object statement at the end of this line, but everything errors out on me. I also thought about putting the results of this into a variable, and then running an IF statement, but that didn't work either. Get-dnsserverresourcerecord only returns the hostname, and I need the FQDN that this line returns. Does anyone know what I should add to the following line to get this to work? $zonename is variable that's working fine. If the one line can't do what I'm looking for, can you point me in the right direction? TIA

    Get-WmiObject -Class MicrosoftDNS_AType -NameSpace Root\MicrosoftDNS -ComputerName 192.168.1.1  -Filter "DomainName = '$zonename'" | Select-Object -property Ownername, IPAddress, Timestamp
  • #62863
    Profile photo of Don Jones
    Don Jones
    Keymaster

    I think I'm possibly not following what it is you want, which this does not do...?

  • #62865
    Profile photo of Dave
    Dave
    Participant

    That line works, but returns the non-static records too. I need a way of only getting the static records.

  • #62866
    Profile photo of Dave
    Dave
    Participant

    Ah – someone in another forum got it, so the correct answer for those wondering is:

    Get-WmiObject -Class MicrosoftDNS_AType -NameSpace Root\MicrosoftDNS -ComputerName 192.168.1.1 -Filter "DomainName = '$zonename' AND TimeStamp = 0" | Select-Object -property Ownername, IPAddress, Timestamp

    Thanks!

  • #62949
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    Its easier if you use the cmdlets from the DNSserver module

    Get-DnsServerResourceRecord -ComputerName W16DC01 -ZoneName 'manticore.org' -RRType A |
    where {-not $_.TimeStamp}

    Also I'd recommend using Get-CimInstance rather than Get-WmiObject

You must be logged in to reply to this topic.