List All DNS Records with Powershell

UPDATED 6/16/2016 Thanks for the comments!

Here’s a nice quick script to list all DNS records in each zone on the DNS server(includes sub-zones):

From the DNS Server

From a Remote DNS Server

From a Remote DNS Server (Output to Tab Delimited File)


12 thoughts on “List All DNS Records with Powershell

  1. Great short script. Thank you for posting it. May I recommend that you name your output file with the extension .CSV since you are exporting CSV data and add the “-ComputerName” parameter to both your Get-DnsServerZone and Get-DnsServerResourceRecord so that it can be run from anywhere not just from the DNS server itself.

    Anyway, thank you for your post

  2. It does not return any IP-addresses to CSV. If you run it without pipeing to anywhere, you can see IP-addressess though. Might be related the properities having sub-properties.

  3. Hello great script, but i have some long entry that when exported they appear like this:

    x._domainkey.cyberoffres TXT 0 00:05:00 k=rsa; p=DEW22WKEJRNLqXXX222DQ98ASDKKGNADCBi…

    Is there a way to export the complete character??

    Best regards

    • For futur generation 🙂 I got my solution here’s what i added

      $DNSServer = “servernameOrIp”
      $Zones = @(Get-DnsServerZone -ComputerName $DNSServer)
      ForEach ($Zone in $Zones) {
      Write-Host “`n$($Zone.ZoneName)” -ForegroundColor “Green”
      $Results = $Zone | Get-DnsServerResourceRecord -ComputerName $DNSServer | Format-Table -AutoSize -Wrap
      echo $Results > “$($Zone.Zo

  4. Is there any way to get this to sort by timestamp? Or at least put the csv so the timestamp is in a separate field? I didn’t see any Parameters to do this:

    [[-Name] ]
    [-ComputerName ]
    [-ZoneScope ]
    [-VirtualizationInstance ]
    [-RRType ]
    [-CimSession ]
    [-ThrottleLimit ]

  5. @ShadowFly: you need to sort the output before writing it down, there’s a separate Sort-Object cmdlet for this, I have added your requirement in the code:
    $DNSServer = “servernameOrIp”
    $Zones = @(Get-DnsServerZone -ComputerName $DNSServer)
    ForEach ($Zone in $Zones) {
    Write-Host “`n$($Zone.ZoneName)” -ForegroundColor “Green”
    $Results = $Zone | Get-DnsServerResourceRecord -ComputerName $DNSServer | Sort-Object Timestamp -Descending | Format-Table -AutoSize -Wrap
    echo $Results > “$($Zone.ZoneName).txt”

  6. May I recommend:

    $DNSServer = “SERVER”
    $Zones = @(Get-DnsServerZone -computername $DNSServer)
    # Get all zone information for a Domain Zone

    $DNS = ForEach ($Zone in $Zones) {
    Get-DnsServerResourceRecord -Zonename $zone.ZoneName -ComputerName $DNSServer | Select-Object hostname, recordType, @{n=’ZoneName’;Expression={$zone.ZoneName}},@{n=’Data’;e={
    $rr = $_
    switch ($rr.RecordType) {
    A’ {$rr.RecordData.IPv4Address}
    CNAME’ {$rr.RecordData.HostnameAlias}
    NS’ {$rr.RecordData.NameServer}
    SOA’ {$rr.RecordData.PrimaryServer}
    SRV’ {$rr.RecordData.DomainName}
    PTR’ {$rr.RecordData.PtrDomainName}
    MX’ {$rr.RecordData.MailExchange}
    AAAA’ {$rr.RecordData.IPv6Address}
    TXT’ {$rr.RecordData.DescriptiveText}

    $DNS | Export-Csv -NoTypeInformation -Path dns.csv

Leave a Reply

Your email address will not be published. Required fields are marked *