Finding Resource Records in a Zone
With the marriage of DNS and
WMI,
sending DNS queries has never been so easy. By using WQL, you can
write complex query routines that would not have been possible
previously. To list all of the resource records on a server, you
simply need to execute the WQL query select * from
MicrosoftDNS_ResourceRecord
against
the target server. The following example shows how to run the query
against the local name server:
set objDNS = GetObject("winMgmts:root\MicrosoftDNS") set objRR = objDNS.ExecQuery("Select * from MicrosoftDNS_ResourceRecord") for Each objInst in objRR WScript.Echo objInst.TextRepresentation next
The
TextRepresentation
method is available to all resource record types since
it’s defined in
MicrosoftDNS_ResourceRecord
. It returns a text
string representing the resource record, such as the following:
www.movie.edu. IN A 192.10.4.5
If you want to limit the query to only a specific zone, change the
WQL query to include criteria for ContainerName
,
such as the following:
Select * from MicrosoftDNS_ResourceRecord
Where ContainerName = 'ZoneName
'
Since Active Directory stores all of the global catalog servers for a
forest and domain controllers for a domain in DNS, you can write
scripts to access this information and integrate it into your
applications. The following example does exactly this by selecting
all SRV records with a particular OwnerName
. To
find all global catalog servers in a forest, you can look up
_ldap._tcp.gc._msdcs
.ForestRootDNSName ...
Get DNS on Windows Server 2003, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.