HowTo: Scripting DNS entries in Windows 2000
Scripting DNS entries in Windows 2000
This article will describe the process that is required to create new DNS entries on Windows 2000 using VB Script.
We can use WMI to list/add/delete & modify entries on the DNS Server. This is a very powerful and usefull functionallity to have especially if you are in the hosting business but even as a web page developer to create new DNS entries simply and easily.
Some prerequisites:
- Windows 2000 Server.
- Windows 2000 DNS server installed.
- WMI DNS provider installed.
The first two prerequisites are probably no problem, but where do you get the WMI DNS provider? The provider can be downloaded for free from ftp://ftp.microsoft.com/reskit/win2000/dnsprov.zip

Installing the DNS provider
Installation of the DNS provider is quite simply and only requires two files.
- dnsprov.dll
- dnsschema.mof
Step/Step instructions to install.
- First we need to copy the DNSprov.DLL and dnsschema.mof to the \WinNT\System32\WBEM folder.
- Then open a command prompt and navigate to the \WinNT\System32\WBEM folder
- At the command prompt type in mofcomp dnsschema.mof this will compile the schema so that WMI knows how to interact with the DNS service.
- After the compile is completed type in RegSvr32 dnsprov.dll to register the DNS provider that is used to implement DNS for WMI.

The WMI provider is now installed. You will need to go this this process of installation on the Windows 2000 DNS server, and also on any clients computers that you wish to use to communicate with the Windows 2000 DNS Server.
Script files included in the ZIP file
- DNSImport.VBS - A script which allows you to import DNS data from a text file or excel spreadsheet.
- DNSrecord.VBS - A script which allows you to add/delete/modify and list DNS Resource Record data for a DNS Zone.
- DNSServer.VBS - A script which allows you to get and set DNS Server information for a machine.
- DNZZones.VBS - A Script which allows you to add/delete/modify and list DNS Zone information for a machine.
The ZIP file also contains a help file in compiled HTML format with some example code and documentation for the DNS provider.
Creating a new DNS Zone
cscript dnszones.vbs Create Primary Forward bob.com /S pdc01 /U administrator /W password
Microsoft (R) Windows Script Host Version 5.1 for Windows Copyright (C) Microsoft Corporation 1996-1999. All rights reserved.
Operation successful. |
The code above uses the DNSZONES.VBS script and will create a Primary, Forward DNS Zone called BOB.COM on the server PDC01 using the administrator account and password. This is required only if you are creating the DNS zone on another computer from where the script is being run from. All of the scripts uses the same format for specifying the server, user account and password.
/S servername /U useraccount /W password
If we now check the DNS server using the DNS server MMC snapin we will see that we have a DNS Zone created called BOB.COM

Adding an A (Anchor) Record to a DNS Zone
| cscript dnsrecord.vbs /add A bob.com iisfaq 192.168.0.3 /S pdc01 /U administrator /W password
Microsoft (R) Windows Script Host Version 5.1 for Windows Copyright (C) Microsoft Corporation 1996-1999. All rights reserved.
Namespace = root\microsoftdns Creating Resource Record... Host Name : iisfaq.bob.com IP Address : 192.168.0.3 DNS Server : pdc01.ADROCK.CO.NZ Zone : bob.com Domain : bob.com TTL : 3600 Operation Successful! |
This time we use the DNSRECORD.VBS script to add an A Record to the DNS zone. We have specified that an A Record be created for the BOB.COM DNS Zone and to specify IISFAQ as the A Record name and that it will point to 192.168.0.3
We now can test this to see if the DNS record has really been created.

The iisfaq.bob.com is fully functioning and being resolved correctly.
There are a lot of options associate with each of the script file and we have only touched the surface.
When dealing with the DNSRECORD.VBS script if you specify no parameters you will get a message like below
cscript dnsrecord.vbs
Microsoft (R) Windows Script Host Version 5.1 for Windows Copyright (C) Microsoft Corporation 1996-1999. All rights reserved.
Error occurred in passing parameters. |
To get help just enter a /? on the command line like this:
| cscript dnsrecord.vbs /?
Microsoft (R) Windows Script Host Version 5.1 for Windows Copyright (C) Microsoft Corporation 1996-1999. All rights reserved.
Gets or sets DNS Resource Record Data.
SYNTAX: DnsRecord operation [/S ] [/U ] [/W ] [/O ]
operation [/list | /add | /delete | /Modify]
For help on a specific operation type:
DnsRecord /list /? DnsRecord /add /? DnsRecord /delete /? DnsRecord /Modify /?
PARAMETER SPECIFIERS: server A machine name. username The current user's name. password Password of the current user. outputfile The output file name. |
Getting help on a specific command is a nice feature of the scripts since there are a large number of parameters. To get help on adding a DNS record specify the command and then /?, the help also provides you with an example of how to use the command.
cscript dnsrecord.vbs /list /?
Microsoft (R) Windows Script Host Version 5.1 for Windows Copyright (C) Microsoft Corporation 1996-1999. All rights reserved.
Lists Resource Record in a domain.
SYNTAX: DnsRecord /List [/S ] [/U ] [/W ] [/O ]
PARAMETER SPECIFIERS: recordtype A resource record type. Valid Types are: A, CNAME, MX, PTR, NS, AAAA, AFSDB, ATMA, HINFO, ISDN M |
|