Get-DnsServerResourceRecord to export IP address to CSV

Hi All,


I am trying to get the Get-DnsServerResourceRecord cmdlet to export A records and CNAME records including the IP address to CSV file.


When I run in the powergui script editor I can see the IP address recorddata however when same command is used to export result to csv the IP is replaced with DnsServerResourceRecordA which is the type of record?

Any help would be fantastic! :-)

Get-DnsServerResourceRecord -ZoneName Zone1 | Where-Object {$_.RecordType -eq "CNAME" -or $_.RecordType -eq "A" } | Export-Csv C:\scripts\DNS.csv -NoTypeInformation

  • Can't test with the cmdlet right now but likely the record is either presented as collection/array or the record itself is incorrectly cast to string.

    try selecting just one object and then call .ToString() on the property that holds the A records.

    like : $o = Get-DnsServerResourceRecord -ZoneName Zone1 |

    Where-Object {$_.RecordType -eq "CNAME" -or $_.RecordType -eq "A" }  |

    select -first




    What do you see? the same thing you see in csv? 

    If so you need to convert the data to string yourself. Most likely by doing: $_.ARecords -join ", "and then add this as property to the object using Add-Member for example. I can show you the code once we identify the issue.  


  • Firstly thank you for responding ! :-)

    When running the command the five attributes below are returned. Now I can do a select on all of the below as they are System.String values however when I do a get-member on RecordData its returned as a


    Not a string value and holds all data in an array. (I think)

    I would like to export all below as is to csv but as the recordData is a different type I cant figure it out! :-(

    HostName   RecordType    Timestamp    TimeToLive      RecordData

    --------     ----------       ---------     ----------       ----------

     COmputer1    A                    0             00:10:00

    I tried the below but IP address then returns an array of all the IP's











    = Get-DnsServerResourceRecord -ZoneName

     Zone1 | `





    {$_.RecordType -eq "CNAME" -or $_.RecordType -eq "A"







    | select Hostname, @{label="IP Address";expression={$o.RecordData.ipv4address}}