powershellwindows-7dnswindows-server-2008-r2

How to Update DNS Records Programatically


I am trying to update a DNS Record which is at (I believe) the following path on the server:

ServerName -> Forward Lookup Zones -> domain.com -> test

Where the DNS record is called test, and is of type Host(A).

I downloaded the DNSShell module from here and tried changing the 'Data' column of the DNS record (which contains an IP address) with this command:

Set-DNSRecord -Identity "test.domain.com"

But I got this error:

Cannot validate argument on parameter 'Identity'. The argument "test.domain.com" does not match the "^\\.\root\MicrosoftDNS:MicrosoftDNS_" pattern. Supply an argument that matches "^\\.\root\MicrosoftDNS:MicrosoftDNS_" and try the command again.

So I updated the Identity parameter as follows:

Set-DNSRecord -Identity "\\Servername\root\MicrosoftDNS:MicrosoftDNS_"

But now I am seeing:

Set-DNSRecord : Specified argument was out of the range of the valid values. Parameter name: Path

When I try adding a -Path, it says there is not such parameter! Does anyone know where I need to add the test.domain.com part of the DNS to tell the command which record to update? The documentation on this module is incomplete for this part of it and I can't seem to find any alternatives.

I can call Get-DNSRecord and see the record I need to update, but any attempts to Set are blocked because I have no idea how these paths are built.

Any help is much appreciated.


Solution

  • I managed to overcome this by using ye olde classic CMD command:

    dnscmd /RecordAdd domain.com recordname RecordType /Aging /OpenAcl A 192.168.0.0
    

    This adds a new record, and seems to do so even when another record with the same name (but different IP) exists.

    So in my case, I will have to use dnscmd to first remove the existing record before adding a new one (as I actually just want to update the IP address of the existing record).

    Command for removing DNS record :

    dnscmd /recorddelete domain.com recordname
    

    More details can be found here.