PowerShell script to add multiple A records in DNS
Recently I am focused on to design and implement ConfigMgr for our company. Unfortunately there are no native support for PowerShell in ConfigMgr yet. So if you see I am “slacking”, you know why!
But I am finishing up a ConfigMgr SP1 setup guide and will share it soon.
Lately our team received a lot requests to add new DNS records for our testing web server, I am getting tired to add A record in DNS manually for those Host headers in IIS. Here is what I come up
#xyz is dns servername
$A = [wmiclass]"\\xyz\root\MicrosoftDNS:MicrosoftDNS_AType"
$DNSServer = "xyz.R-test.com"
$Zone = "R-Test.com"
$class = 1
$TTL = 3600
#This is your web server IP Address
$IPAddress = "192.168.1.88"
$Sites = Get-content WebSites.txt
Foreach ($Site in $Sites)
{
$A.CreateInstanceFromPropertyData($DNSserver, $zone, $Site, $class, $ttl, $IPAddress)
}
The WebSites.txt is something look like this:
whatever1.R-test.comwhatever2.R-test.comwhatever3.R-test.com
whatever4.R-test.com
…
If whateverx already has a DNS A record, you will get something like this:
Exception calling "CreateInstanceFromPropertyData" : "Generic failure "
At C:\Documents and Settings\Administrator.RELATED-TEST\My Documents\AddDNSARecords.ps1:13 cha
+ $A.CreateInstanceFromPropertyData( <<<< $DNSserver, $zone,$Site, $class, $ttl, $IPAddress)
Thanks Richard Siddaway for his post Here