Home‎ > ‎Software‎ > ‎Microsoft‎ > ‎

DNS Exporter

Export DNS with Timestamps so that I can determine what will be deleted when enabling scavenging.

$DNSlist = import-csv -Delimiter `t C:\DNS_Zone_Export.txt
$Date = $(Get-Date).AddDays(-14)
$DeletableDNSRecords = $DNSlist | where {$_."TimeStamp (Friendly)" -lt $date} | select OwnerName, "TimeStamp (Friendly)"

foreach ($machine in $DeletableDNSRecords) 
	$pingable=$(Test-Connection -Quiet -ComputerName $machine.OwnerName)
	write-host $machine.OwnerName "," $pingable
	$machine | Add-Member -membertype noteproperty -name Pingable -Value $pingable 

$DeletableDNSRecords | where {$_.pingable -eq "True"} | Select OwnerName

LDAP Search for dns timestamp

*note the timestamp for deletion is not stored in AD at least I can't find an attribute that corresponds to that value, was able to get the info with a powershell query below.

ldapsearch -x -LLL -P 3 -h DC01.blah.corp -D "kcurran-admin@blah.corp" -W -b "DC=ForestDnsZones,DC=blah,DC=root" -s sub "(&(objectClass=dnsNode)(name=servername))" name cn whenchanged modifyTimeStamp

Right click on the root
select connect to
set Name ForestDNSZones
set Connection Point DC=ForestDnsZones,DC=blah,DC=root

Get-WmiObject -namespace "root\MicrosoftDNS" -Credential $cred -ComputerName DNSServer -Class "MicrosoftDNS_AType" -filter "ContainerName='blahnet.corp' AND OwnerName='server.blahnet.corp'"

$cred = Get-Credential
Get-WmiObject -namespace "root\MicrosoftDNS" -Credential $cred `
    -ComputerName $DNSServer -Class "MicrosoftDNS_AType" `
    -filter "ContainerName='blahnet.corp' AND OwnerName='server.blahnet.corp'" | 
    Select-Object OwnerName, @{n="TimeStamp";e={((Get-Date("01/01/1601")).AddHours($_.TimeStamp)).ToLocalTime()}}

dnscmd dnsservername /enumrecords blahnet.corp servername /Type A /additional
Returned records:
@ [Aging"3598301] 3600 A
Command completed successfully

Dump a list of all dns records to a text file.
dnscmd dnsservername /enumrecords blahnet.corp @ /Type A /additional > foo.csv