Author Posts

January 11, 2018 at 12:54 pm

Hi All,

I have a small query. I am trying to export data from below powershell to CSV. The output on screen shows proper IP address but in CSV it show just 01:00:00. How do I get IP address in CSV as well. Any help would be great.

Get-DNSServerResourceRecord domain.com | where-object { $_.TimeStamp –eq $null} | Export-CSV C:\Powershell\StaticDNSRecords3.csv

Regards,
Neville

January 11, 2018 at 1:13 pm

It's because RecordData isn't a simple value. It's a CIM Instance property object.

PS C:\Users\lwinadmin> Get-DnsServerResourceRecord -ZoneName lwinerd.local | Where-Object TimeStamp -NE $null | Select-O
bject RecordData

RecordData
----------
DnsServerResourceRecordA
DnsServerResourceRecordSrv
DnsServerResourceRecordSrv
DnsServerResourceRecordSrv
DnsServerResourceRecordSrv
DnsServerResourceRecordSrv
DnsServerResourceRecordSrv
DnsServerResourceRecordSrv
DnsServerResourceRecordSrv
DnsServerResourceRecordSrv
DnsServerResourceRecordA
DnsServerResourceRecordA
DnsServerResourceRecordA
DnsServerResourceRecordA
DnsServerResourceRecordA
DnsServerResourceRecordA
DnsServerResourceRecordA
DnsServerResourceRecordA
DnsServerResourceRecordSrv
DnsServerResourceRecordSrv
DnsServerResourceRecordA
DnsServerResourceRecordSrv
DnsServerResourceRecordSrv

You can expand the object and extract the IP Addresses from there.

PS C:\Users\lwinadmin> Get-DnsServerResourceRecord -ZoneName lwinerd.local | Where-Object TimeStamp -NE $null | Select-O
bject -ExpandProperty RecordData

IPv4Address PSComputerName
----------- --------------
10.1.2.32









10.1.2.4
10.1.2.5
10.1.2.6
10.1.2.10
10.1.2.7
10.1.2.8
10.1.2.9
10.1.2.32


10.1.2.32




PS C:\Users\lwinadmin>

January 12, 2018 at 1:43 am

If you are after the hostname and IPA. You can do this..

    Clear-Host
    Get-DnsServerResourceRecord -ZoneName  $env:USERDNSDOMAIN | 
    Where { $_.TimeStamp -and $_.RecordData.ipv4address -NE $null } |
    select Hostname, @{label="IPAddress";expression={$_.RecordData.ipv4address}}

January 12, 2018 at 10:10 am

Thank you both. It was helpful to get me to my final script.

Get-DNSServerResourceRecord domain.com | where-object { $_.TimeStamp –eq $null} | 
select Hostname,RecordType,DistinguishedName, @{label="IPAddress";expression={$_.RecordData.ipv4address}} | 
Export-CSV C:\Powershell\StaticDNSRecords1.csv