IP address exported to CSV shows 01:00:00

Welcome Forums General PowerShell Q&A IP address exported to CSV shows 01:00:00

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
10 months, 1 week ago.

  • Author
    Posts
  • #91225

    Participant
    Points: 12
    Rank: Member

    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

    Keymaster
    Points: 12
    Team Member
    Rank: Member

    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

    Participant
    Points: 225
    Helping Hand
    Rank: 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

    Participant
    Points: 12
    Rank: Member

    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
    

The topic ‘IP address exported to CSV shows 01:00:00’ is closed to new replies.