WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WMI
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Modify DNS Entries

 Keywords: DNS Host A Record Changes Modify Failover Entries Create modify Delete MicrosoftDNS \root\MicrosoftDNS MicrosoftDNS_AType WMI

Question:

We want to automate host A record changes within our Microsoft DNS entries for failover purposes. I am trying to find a method to Create, Change or Delete DNS entries within Microsoft’s Integrated DNS. Any ideas? (DNS is for Windows Server 2012)

Example of task to perform:

 
ServerA.Domain.com                                    1.1.1.1                   TTL=20

Push Change for fail over
ServerA.Domain.com                                    2.2.2.2                   TTL=5

Push change to Fail back
ServerA.Domain.com                                    1.1.1.1                   TTL=20
If it possible to change the TTL that would be a plus. If not just updating the record will do the job.Any ideas?

Answer:

I believe this can be accomplished on Windows Server 2012 using WMI. For example:
; Returns information about the host address (A) resource records on a DNS server.
strComputer = "."
objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" : strComputer : "\root\MicrosoftDNS")
colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_AType")
ForEach objItem In colItems
    data =  "IP Address: " : objItem.IPAddress : @LF
    data = data :  "Owner Name: " : objItem.OwnerName : @LF
    data = data :  "Container Name: " : objItem.ContainerName : @LF
    data = data :  "DNS Server Name: " : objItem.DnsServerName : @LF
    data = data :  "Domain Name: " : objItem.DomainName : @LF
    data = data :  "Record Class: " : objItem.RecordClass : @LF
    data = data :  "Record Data: " : objItem.RecordData : @LF
    data = data :  "Text Representation: " : objItem.TextRepresentation : @LF
    data = data :  "Time-to-Live: " : objItem.TTL : @LF
    Pause( '\root\MicrosoftDNS', data )
Next
Here is a link to the Modify method: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682181(v=vs.85).aspx

The code might look something like this:

; Modify the record
;
; Connect to the WMI Service
strComputer = "."
objWMIService = ObjectGet("winmgmts:{impersonationLevel=impersonate}!\\" : strComputer : "\root\MicrosoftDNS")
; Run a query to get the record we want to change
colItems = objWMIService.ExecQuery("SELECT * FROM MicrosoftDNS_AType WHERE ContainerName='domain.example' AND OwnerName='test.domain.example'", , 48)
; Loop through the results
ForEach objItem In colItems
  ; Modify the record
  ttl = objItem.TTL
  objItem.Modify( ttl, "1.2.3.4" )
Next
Exit
Reference: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682123(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/windows/desktop/ms682132(v=vs.85).aspx http://technet.microsoft.com/en-us/library/ee692588.aspx http://gallery.technet.microsoft.com/scriptcenter/e08cfb59-2a10-4582-bc2d-381bbba25f4f http://www.indented.co.uk/2008/10/23/modifying-dns-records-with-wmi/
Article ID:   W18510
Filename:   Modify DNS Entries .txt
File Created: 2014:06:24:08:39:44
Last Updated: 2014:06:24:08:39:44