get-dnsserverresourcerecord

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

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?

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”)}

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

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



}

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?

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