locked
How to find all properties of RecordData from Get-DnsServerResourceRecord RRS feed

  • Question

  • When I use Get-DnsServerResourceRecord I can obviously get the zone details, but I'm trying to do a select-object on the RecordData column which isn't straight forward since it's not a simple text string.

    What I've found so far... I can query specific properties of RecordData to query types of record, for instance :

    Get-DnsServerResourceRecord -zonename "myzone.com" | where-object {$_.RecordData.nameserver -match "ns1"}
    
    Get-DnsServerResourceRecord -zonename "myzone.com" | where-object {$_.RecordData.ipv4address -match "192.168"}

    will let me query NS records and A record IP addresses.

    How do I find the other properties available from RecordData other than nameserver and ipv4address? Presumably there must also be properties for MX records, CNAME records, Text records, IPv6 records etc, but I can't work out how to find what they are.

    Thursday, August 8, 2013 6:44 AM

Answers

  • just a guess but could you try

    $record = Get-DnsServerResourceRecord -zonename "myzone.com"
    $record.RecordData | get-member

    Thursday, August 8, 2013 12:51 PM

All replies

  • just a guess but could you try

    $record = Get-DnsServerResourceRecord -zonename "myzone.com"
    $record.RecordData | get-member

    Thursday, August 8, 2013 12:51 PM
  • Superb guess! Had tried so many combinations, but it seems not that one! Doh!

    Thank you, that gave me what I was after. Running that spits out the details for each type of record, so for instance for CNAME's you get :

    -----
       TypeName: Microsoft.Management.Infrastructure.CimInstance#ROOT/Microsoft/Windows/DNS/DnsServerResourceRecordCName

    Name                      MemberType Definition
    ----                      ---------- ----------
    Clone                     Method     System.Object ICloneable.Clone()
    Dispose                   Method     void Dispose(), void IDisposable.Dispose()
    Equals                    Method     bool Equals(System.Object obj)
    GetCimSessionComputerName Method     string GetCimSessionComputerName()
    GetCimSessionInstanceId   Method     guid GetCimSessionInstanceId()
    GetHashCode               Method     int GetHashCode()
    GetObjectData             Method     void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtim...
    GetType                   Method     type GetType()
    ToString                  Method     string ToString()
    HostNameAlias             Property   string HostNameAlias {get;set;}
    PSComputerName            Property   string PSComputerName {get;}

    -----

    So in addition to nameserver and ipv4address I've now found HostNameAlias for CNAME, MailExchange for MX, DescriptiveText for TXT and DomainName for SRV .

    Also found that it only spits out the properties relating to records held within the domain you use in the query, so if you need to find every record type you'd need to ensure you have at least one of each record in your domain first.

    Thursday, August 8, 2013 6:52 PM
  • A gift for all! 

    Hours of work!!

    $dnszones = Get-DnsServerZone | Select ZoneName
    ForEach ($zone in $dnszones) { $data = New-Object System.Object
    $ZoneName = $Zone.ZoneName
    $data = Get-DnsServerResourceRecord $ZoneName
    foreach ($registros in $data){
            $data = $ZoneName
            $data += ","
            $data += $Hostname = $registros.hostname;
            $data += ","
            $data += $RecordType = $registros.recordType;
            $data += ","
            
            if ($RecordType -like "PTR"){
                $data += $registros.RecordData.PtrDomainName
                }
                elseif ($RecordType -like "A"){
                $data += $IPAddress = $([system.version]($registros.RecordData.ipv4address.IPAddressToString));
                }
                elseif ($RecordType -like "CNAME"){
                $data += $registros.RecordData.HostNameAlias;
                }
                elseif ($RecordType -like "NS"){
                $data += $registros.RecordData.nameserver;
                }
                elseif ($RecordType -like "MX"){
                $data += $registros.RecordData.MailExchange;
                }
                elseif ($RecordType -like "SOA"){
                $data += $registros.RecordData.PrimaryServer;
                }
                elseif ($RecordType -like "SRV"){
                $data += $registros.RecordData.DomainName;
                }
            $data | out-file -FilePath c:\ExportDNS\DNSRecords.csv -Append
         }

    }

    Tuesday, July 14, 2020 7:45 PM