Today I needed to change – using a script – a type A entry in my DNS.
Using WMI, you can get MicrosoftDNS_AType class that represents an A record saved in a Microsoft DNS server. The class has a Modify method you can use to change TTL value and IP address of that record.
First, you have to get using Powershell a MicrosoftDNS_AType object that represents the record you need to change:
$dnsEntry = Get-WmiObject -ComputerName myDNSServer -Namespace "root\MicrosoftDNS" -Class "MicrosoftDNS_AType" -Filter "OwnerName = 'myrecord.mydomain.com'" |
Change:
- ComputerName, name or IP address of your DNS server
- OwnerName, A record (including domain suffix) to be changed
Now you can invoke Modify to change the IP address, keeping the original TTL value:
$modifiedDnsEntry = $dnsEntry.Modify($dnsEntry.TTL, "192.168.1.1") |