Creating Resource Records

With the DNS Provider, creating resource records can be done in a couple of steps. The CreateInstanceFromTextRepresentation method takes the following parameters: the domain name of the name server to create the record on, the domain name of the zone to add the record to, and the textual representation of the resource record. It also provides an out parameter that is a MicrosoftDNS_ResourceRecord object representing the newly created record.

The following example goes through the process of creating both an A and a PTR record. Both records are typically necessary when adding a new host to DNS:

option explicit Dim strRR, strReverseRR, strDomain, strReverseDomain ' A record to add strRR = "matrix.movie.edu. IN A 192.168.64.13" strDomain = "movie.edu" ' PTR record to add strReverseRR = "13.64.168.192.in-addr.arpa IN PTR matrix.movie.edu" strReverseDomain = "168.192.in-addr.arpa." Dim objDNS, objRR, objDNSServer, objRR2, objOutParam set objDNS = GetObject("winMgmts:root\MicrosoftDNS") set objRR = objDNS.Get("MicrosoftDNS_ResourceRecord") set objDNSServer = objDNS.Get("MicrosoftDNS_Server.Name="".""") ' Create the A record Dim strNull strNull = objRR.CreateInstanceFromTextRepresentation( _ objDNSServer.Name, _ strDomain, _ strRR, _ objOutParam) set objRR2 = objDNS.Get(objOutParam) WScript.Echo "Created Record: " & objRR2.TextRepresentation set objOutParam = Nothing ' Create the PTR record strNull = objRR.CreateInstanceFromTextRepresentation( _ objDNSServer.Name, ...

Get DNS on Windows Server 2003, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.