get-dnsserverresourcerecord

This topic contains 6 replies, has 4 voices, and was last updated by Profile photo of Dan Potter Dan Potter 1 year, 11 months ago.

  • Author
    Posts
  • #25933
    Profile photo of Dan Potter
    Dan Potter
    Participant

    Anyone know why this returns two objects whenever using where?

    PS C:\PSScripts> Get-DnsServerResourceRecord -ComputerName dnsserver -ZoneName myzone.com -name dptest

    HostName RecordType Timestamp TimeToLive RecordData
    ——– ———- ——— ———- ———-
    dptest A 0 01:00:00 10.1.2.3

    PS C:\PSScripts> Get-DnsServerResourceRecord -ComputerName dnsserver -ZoneName myzone.com | ? {$_.hostname -like "dptest*"}

    HostName RecordType Timestamp TimeToLive RecordData
    ——– ———- ——— ———- ———-
    dptest A 0 01:00:00 10.1.2.3
    dptest.myzone.com A 0 01:00:00 10.1.2.3

  • #25934
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    I can't reproduce your result

    £> Get-DnsServerResourceRecord -ZoneName manticore.org -Name w12r2sus

    HostName RecordType Timestamp TimeToLive RecordData
    ——– ———- ——— ———- ———-
    w12r2sus A 04/06/2015 11:00:00 00:20:00 10.10.54.203

    I only get a single result back. I'm running Windows Server 2012 R2 as my DNS server – fully patched

    Have you manually checked your DNS to see if you have duplicate records?

  • #25937
    Profile photo of Dan Potter
    Dan Potter
    Participant

    now try Get-DnsServerResourceRecord -ZoneName manticore.org | ? {$_.hostname -like " w12r2sus*"}

    Where this becomes an issue specifically.

    Get-DnsServerResourceRecord -ComputerName dnsserver -ZoneName zone.com | ? {($_.timestamp -gt [datetime]"1/1/2013") -and ($_.timestamp -lt [datetime]"1/1/2014")}

  • #25938
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    Still a single record

    £> Get-DnsServerResourceRecord -ZoneName manticore.org -ComputerName w12r2scdc01 | ? {$_.Hostname -like 'w12r2sus*'}

    HostName RecordType Timestamp TimeToLive RecordData
    ——– ———- ——— ———- ———-
    W12R2SUS A 26/08/2014 15:00:00 00:20:00 10.10.54.203

  • #25942
    Profile photo of Dan Potter
    Dan Potter
    Participant

    strange...

    Here is the full code. I have two objects for each dns entry (one hostname, one fqdn) in the csv when it's finished.

    {
    
    
    function get-dnsinfo{
    
    [CmdletBinding()]
    param (
      
     
      
       [parameter(Mandatory=$True)]
       [String]$StartYear,
    
       [Parameter(Mandatory=$True)]
       [string]$EndYear,
    
       [Parameter(Mandatory=$False)]
       [Switch]$includesrv 
    
    )
    
    
    $start = [datetime]"1/1/$StartYear"
    $end = [datetime]"1/1/$endYear"
    
    
    
    
    if($includesrv){
    
    $dns = Get-DnsServerResourceRecord -ComputerName dnsserver -ZoneName myzone.com | ? {($_.timestamp -gt $start) -and ($_.timestamp -lt $end)}
    
    }else{
    
    $dns = Get-DnsServerResourceRecord -ComputerName dnsserver -ZoneName myzone.com | ? {($_.timestamp -gt $start) -and ($_.timestamp -lt $end) -and ($_.recordtype -ne 'SRV')}
    
    }
    
    
    
    foreach($i in $dns){
    
    $p = [ordered]@{
    
    hostname = $i.hostname
    recordtype = $i.recordtype
    timestamp = $i.timestamp
    timetolive = $i.timetolive
    Cname = $i.RecordData.hostnamealias
    ip = $i.RecordData.ipv4address
    IPv6 = $i.RecordData.ipv6address
    
    }
    
    
    New-Object psobject -Property $p
    
    
    }
    
    
    }
    
    
    get-dnsinfo -startyear 2012 -endyear 2013 -includesrv |export-csv yourfilename.csv -notypeinformation
    
    
    
    }
  • #26092
    Profile photo of Richard Diphoorn
    Richard Diphoorn
    Participant

    Is this somehow related? I also can reproduce your problem here. The customer I'm at the moment has a subdomain matching the zone name. Perhaps you have the same issue there?

    http://www.briantist.com/errors/get-dnsserverresourcerecord-returns-duplicate-records-when-sub-domain-matching-zone-exists/

  • #26132
    Profile photo of Dan Potter
    Dan Potter
    Participant

    Same behavior although I don't have any subs in this zone.

You must be logged in to reply to this topic.