Listing the Zones on a Server
The last zone example we’ll
show
lists the configured zones on a specific name server. To make the
following example a little more robust, we’ve added
logic to make the script configurable so it can be run against any
name server using the specified credentials. That is accomplished by
using the ConnectServer
method on the
SWbemLocator
object.
strServer = "terminator.movie.edu" strUsername = "dnsadmin" strPassword = "dnspwd" Set objLocator = CreateObject("WbemScripting.SWbemLocator") Set objDNS = objLocator.ConnectServer(strServer, "root\MicrosoftDNS", _ strUsername, strPassword) set objDNSServer = objDNS.Get("MicrosoftDNS_Server.Name="".""") set objZones = objDNS.ExecQuery("Select * from MicrosoftDNS_Zone " & _ "Where DnsServerName = '" & _ objDNSServer.Name & "'") WScript.Echo objDNSServer.Name for each objZone in objZones WScript.Echo " " & objZOne.Name next
To retrieve the list of zones, we used a WQL query with
ExecQuery
to find all
MicrosoftDNS_Zone
objects that had a
DnsServerName
equal to the name of the server we
are connecting
to.
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.