Get a dump of all DNS records from a DNS server

Have you ever needed to get a list of all records from your DNS server? Maybe you need to migrate the records to a new server (powershell can do that, too!) or maybe you just need it for your documentation. Whatever the reason, I wrote a little script to get the information. Change the destination / file name at the end of the script as needed.

$dnszones = Get-DnsServerZone | Select ZoneName
$OutArray = @()

ForEach ($zone in $dnszones) {
	$ZoneName = $Zone.ZoneName
	$ZoneData = Get-DnsServerResourceRecord $ZoneName | ?{$_.RecordType -eq "A"}
	ForEach ($record in $zoneData) {
		$HostName = $record.HostName
		$ipAddress = $record.RecordData.ipV4Address

		$OutArray += New-Object psCustomObject -Property @{
		'Zone' = $ZoneName
		'HostName' = $HostName
		'IPAddress' = $ipAddress
		} | Select Zone, HostName, IPAddress
	}
}
$OutArray | Export-Csv -NoTypeInformation c:\temp\DNSRecords.csv
Advertisements
Tagged with: , ,
Posted in Powershell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: