Taking a Dump (DNS)

Since I started coding powershell, I was under the impression there was no magic way to obtain all DNS records of a certain subdomain from Microsoft DNS. As a result, I was using the dnscmd.exe command and some text mangling to generate a list of hosts. The code I used is below:

Which did the job very well….until one day dnscmd.exe stopped working

I can’t explain why dnscmd.exe stopped working, all I do know is that despite everything I tried, powershell refused to acknowledge the command existing, even when giving direct paths.

So it was kind of embarrassing when digging around and asking colleagues I found that I could get the same information in one line of WMI code. Whilst I was aware that the WMI Classes existed, I had been led to believe they required installation on every MSDNS Server, which I knew would not get approved through change management.

Anyway, the code to enumerate all the hosts in a particular subdomain is:

$DNSRecords = gwmi -ComputerName ns1.mydomain.com -Namespace root\microsoftDNS -Query (‘select OwnerName, IPAddress from MicrosoftDNS_AType where DomainName = “subdomain.mydomain.com”)

Well I thought that was pretty neat anyway.

One thought on “Taking a Dump (DNS)

  1. Pingback: Episode 118 – James Hamilton and Thomas Lee on PowerShell Use in the Hotmail Team « PowerScripting Podcast

Comments are closed.