SideBar    Using WMI to Automatically Configure DNS
DOWNLOAD THE CODE:
Download the Code 37719.zip

Adam identified the final piece of the puzzle when he realized that AD stores all records that read (same as parent folder) in one attribute as an array. An example of this type of record would be the Start of Authority (SOA), which AD automatically creates and, therefore, didn't need to be scripted. After decoding all the DNS information, Adam just needed to write the math to determine all the decimal values.

Dns.vbs
The dns.vbs script opens a connection directly into Microsoft DNS and creates all the information necessary for a new Web site, including a new DNS forward lookup zone, an MX record, and four hosts. Each host links a name to an IP address. The script defaults to setting up a parent host named foo.com, a WWW host named www.foo.com, a MAIL host named mail.foo.com, a WEBMAIL host named webmail.foo.com, and an FTP host named ftp.foo.com. (You can customize each host name and IP address in the script.)

Dns.vbs starts by dimensioning variables. Next, as the code at callout A in Listing 1 shows, the script gives you an "opt out" choice with a message box so that you don't accidentally run the script. The script then instantiates ads.dll, the MSDN conversion utility. After completing this process, the script assigns values (i.e., names and IP addresses) to variables for later use. This part of the script is the only section you need to edit for your needs. The code at callout B contains several sample values and descriptions.

At this point, the script uses the user-defined DNS variables to do calculations, string manipulations, and parsing and converts some of the data to hex format. After the initial calculations are complete, the script connects to AD and creates DNS objects. As the code at callout C shows, the script creates the objects for the DNS zone first. Notice that the script releases COM objects from memory by setting them to Nothing. Because COM components consume large amounts of memory, cleaning up after them is good programming practice.

Next, the script creates the MX record and parent host after performing some complicated computations. Because these two values are saved in the same attribute, the script creates an array and saves the values, as the code at callout D shows.

After creating the MX record and parent host (A) record, the script creates the remaining hosts: WWW, MAIL, and WEBMAIL. The code at callout E shows how the WWW record is created. Finally, if you set FTP to "YES" in the variables section at the beginning of the script, the script creates the FTP host (A) record, as the code at callout F shows.

To run the script, use cscript.exe. From the command line, navigate to the folder in which you placed the dns.vbs script, then type

Cscript dns.vbs

You must log on with domain administrator permissions to run the script. Figure 1 shows dns.vbs running. Notice that appropriate screen I/O appears onscreen to alert the user where the dns.vbs script is in the process of running. The script runs quickly (i.e., in a few seconds), depending on your network configuration.

After the script finishes running, you can check the resulting configurations in DNS. Launch the MMC DNS server snap-in (go to Start, Programs, Administrative Tools, then select DNS). Expand the Forward Lookup Zones folder to see the DNS configuration you've automated. Figure 2 shows the resulting DNS configuration of foo.com that the script created using the sample values provided.

A Time-Saver
Because Adam's company creates multiple IIS Web sites every week, Adam now saves a lot of time by automating the DNS configuration on each new site. Dns.vbs demonstrates the power of scripting and proves that even the most abstract administration tools can be easily built.

End of Article

Prev. page     1 [2]     next page -->



You must log on before posting a comment.

If you don't have a username & password, please register now.

Reader Comments

<P>Good article. Enough to get me started. I'm going to have to duplicate most of his work unfortunately. Any way Adam could have shared his research on how to translate the DNSRecord property?</P>

<P>One other thing, the article should have mentioned where to find DNS in ADSIEdit. Took me a good 15 minutes to find it in Domain - DC=Whatever,DC=com - System - MicrosoftDNS</P>

Ron Rosenkoetter

 
 

ADS BY GOOGLE