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


Flag indicating whether dynamic updates are allowed.


Flag indicating whether the zone was auto-created.


Name of zone file.


If TRUE, WINS record replication is disabled.


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


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


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


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


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


Servers allowed to receive zone transfers.


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


If TRUE, zone has expired (or shutdown).


Flag indicating whether zone uses WINS lookups.


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

Table 27-4. MicrosoftDNS_Zone class methods

Method name

Method description


Age part or all of a zone.


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


Create a new zone.


Forces secondary to update its zone from master.


Get distinguished name of the zone.


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


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


Specify list of secondaries.


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


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


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
   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"
      if objProp.IsArray = TRUE then
         For I = LBound(objProp.Value) to UBound(objProp.Value)
             wscript.echo " " & objProp.Name & " : " & objProp.Value(I)
         wscript.echo " " & objProp.Name & " : " & objProp.Value
      end if
   end if 
' Modify the zone
objDNSZone.AllowUpdate = 1
WScript.Echo ""
if Err then
   Wscript.Echo "Error occurred: " & Err.Description
   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

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.

    Part II: Designing an Active Directory Infrastructure
    Part III: Scripting Active Directory with ADSI, ADO, and WMI