IP address exported to CSV shows 01:00:00

This topic contains 3 replies, has 3 voices, and was last updated by  Neville D’Souza 4 months, 1 week ago.

  • Author
    Posts
  • #91225

    Neville D’Souza
    Participant

    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

  • #91228

    Will Anderson
    Keymaster

    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>
    
  • #91273

    postanote
    Participant

    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}}
    
  • #91286

    Neville D’Souza
    Participant

    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
    

You must be logged in to reply to this topic.