[ Team LiB ] |
14.4 Zone ClassesThe MicrosoftDNS_Zone class offers a plethora of properties and methods to aid in managing your zones. Even if you are using AD-integrated zones, which help reduce the amount of work required to maintain DNS, inevitably you need to configure a zone's settings or create additional zones. In Tables Table 14-3 and Table 14-4, available properties and methods for the MicrosoftDNS_Zone class are listed.
14.4.1 Creating a ZoneCreating a zone with the DNS Provider is a straightforward operation. You need to get a WMI object for the DNS namespace, instantiate an object from the MicrosoftDNS_Zone class, and call CreateZone on that object. The next example shows how to do this: strNewZone = "movie.edu." strServer = "terminator.movie.edu" on error resume next set objDNS = GetObject("winMgmts:\\" & strServer & "\root\MicrosoftDNS") set objDNSZone = objDNS.Get("MicrosoftDNS_Zone") strNull = objDNSZone.CreateZone(strNewZone,0,TRUE) if Err then WScript.Echo "Error occurred creating zone: " & Err.Description else WScript.Echo "Zone created . . . " end if The three parameters we passed into CreateZone include the zone name, the zone type flag, and the AD-integrated flag. A zone type of 0 creates a primary zone. When the AD-integrated flag is set to true, the primary zone is AD-integrated; if it is false, it is a standard primary. At the time of this writing, Microsoft had conflicting documentation about these parameters and their valid values. Refer to the MSDN Library for more information; hopefully, they'll get it straight eventually. 14.4.2 Configuring a ZoneConfiguring a zone is not too different from configuring a name server. The primary difference is in how you instantiate a MicrosoftDNS_Zone object. In order to use the Get method on a WMI object, you have to specify the keys for the class you want to instantiate. For the MicrosoftDNS_Zone class, the keys include ContainerName, DnsServerName, and Name. In this case, ContainerName and Name are both the name of the zone. We retrieve DnsServerName by getting a MicrosoftDNS_Server object as we've done earlier in the chapter. The following example lists all of the properties of the movie.edu zone before it modifies the AllowUpdate property and commits the change: strZone = "movie.edu." strServer = "terminator.movie.edu" on error resume next set objDNS = GetObject("winMgmts:\\" & strServer & "\root\MicrosoftDNS") set objDNSServer = objDNS.Get("MicrosoftDNS_Server.Name="".""") set objDNSZone = objDNS.Get("MicrosoftDNS_Zone.ContainerName=""" & strZone & _ """,DnsServerName=""" & objDNSServer.Name & _ """,Name=""" & strZone & """") ' List all of the properties of the zone Wscript.Echo objDNSZone.Name for each objProp in objDNSZone.Properties_ if IsNull(objProp.Value) then Wscript.Echo " " & objProp.Name & " : NULL" else if objProp.IsArray = TRUE then For I = LBound(objProp.Value) to UBound(objProp.Value) wscript.echo " " & objProp.Name & " : " & objProp.Value(I) next else wscript.echo " " & objProp.Name & " : " & objProp.Value end if end if next ' Modify the zone objDNSZone.AllowUpdate = 1 objDNSZone.Put_ WScript.Echo "" if Err then Wscript.Echo "Error occurred: " & Err.Description else WScript.Echo "Change successful" end if 14.4.3 Listing the Zones on a ServerThe 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. |
[ Team LiB ] |