DekGenius.com
[ Team LiB ] Previous Section Next Section

27.3 Creating and Manipulating Zones

The MicrosoftDNS_Zone class provides 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 it takes to maintain DNS, you will inevitably need to configure settings on a zone or create additional zones. In Table 27-3 and Table 27-4, the list of available properties and methods for the MicrosoftDNS_Zone class are presented.

Table 27-3. MicrosoftDNS_Zone class properties

Property name

Property description

AllowUpdate

Flag indicating whether dynamic updates are allowed.

AutoCreated

Flag indicating whether the zone was auto-created.

DataFile

Name of zone file.

DisableWINSRecordReplication

If TRUE, WINS record replication is disabled.

MastersIPAddressesArray

If zone is a secondary, this contains the list of master servers to receive updates from.

Notify

If set to 1, the master server will notify secondaries of zone updates.

NotifyIPAddressesArray

Servers that will be notified when there are updates to the zone.

Paused

Flag indicating whether the zone is paused and therefore not responding to requests.

Reverse

If TRUE, zone is a reverse (in-addr.arpa) zone. If FALSE, zone is a forward zone.

SecondariesIPAddressesArray

Servers allowed to receive zone transfers.

SecureSecondaries

Flag indicating whether zone transfers are allowed only to servers specified in SecondariesIPAddressesArray.

Shutdown

If TRUE, zone has expired (or shutdown).

UseWins

Flag indicating whether zone uses WINS lookups.

ZoneType

Type of zone. It will be either DS Integrated, Primary, or Secondary.

Table 27-4. MicrosoftDNS_Zone class methods

Method name

Method description

AgeAllRecords

Age part or all of a zone.

ChangeZoneType

Convert zone to one of the following types: DS integrated, Primary, Secondary, Stub, Stub-DS integrated, or Forward.

CreateZone

Create a new zone.

ForceRefresh

Forces secondary to update its zone from master.

GetDistinguishedName

Get distinguished name of the zone.

PauseZone

Causes the DNS server to not respond to queries for the zone.

ReloadZone

Reload the contents of the zone. This may be necessary after making changes to a zone that you want to take effect immediately.

ResetSecondaries

Specify list of secondaries.

ResumeZone

Causes the DNS server to start responding to queries for the zone again.

UpdateFromDS

Reloads the zone information from Active Directory. This is only valid for AD-integrated zones.

WriteBackZone

Save zone data to a file.

27.3.1 Creating a Zone

Creating a zone with the DNS provider is a straightforward operation. You simply 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:

on error resume next
   
strNewZone = "mycorp.com."
   
Set objDNS = GetObject("winMgmts: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, zone type flag, and DS-Integrated flag. A zone type of 0 means to create a primary zone. When the DS-Integrated flag is set to true, the primary zone will be AD-integrated; if it is false, it will be 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 will get it right eventually.

27.3.2 Configuring a Zone

Configuring a zone is not too different from configuring a server. The primary difference is how you instantiate a MicrosoftDNS_Zone object. To use the Get( ) method on a WMI (SWbemServices) 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 the name of the zone. The DnsServerName we retrieve by getting a MicrosoftDNS_Server object as we've done earlier in the chapter.

Example 27-2 first lists all of the properties of the mycorp.com. zone before it modifies the "AllowUpdate" property and commits the change.

Example 27-2. Configuring a zone
on error resume next
   
strZone = "mycorp.com."
   
Set objDNS = GetObject("winMgmts: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

27.3.3 Listing the Zones on a Server

The last zone example we will show lists the configured zones on a specific DNS 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 DNS server. That is accomplished by using the ConnectServer method on the SWbemLocator object.

strServer = "dns1.mycorp.com"
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 ] Previous Section Next Section