Export all hosts from DNS Manager using Powershell

Solution 1:

I've used DNSShell before. http://dnsshell.codeplex.com/. To get all A records in a zone you can do this:

Get-DnsRecord -RecordType A -ZoneName FQDN -Server ServerName

To get this into a text file:

Get-DnsRecord -RecordType A -ZoneName FQDN -Server ServerName | % {Add-Content -Value $_ -Path filename.txt}

Solution 2:

Another method I don't see mentioned yet:

Get-WmiObject -Namespace Root\MicrosoftDNS -Query "SELECT * FROM MicrosoftDNS_AType WHERE ContainerName='domain.com'"

WMI is good to remember when you can't download DnsShell for some reason, or if you're on an older version of Powershell that doesn't have the baked-in Cmdlets, or if you're targeting an older version of Windows Server.