Using PowerShell, in Active Direcotry, how would I change all the DNS A records that have a given IP to a new IP?
Posted
by
djsumdog
on Server Fault
See other posts from Server Fault
or by djsumdog
Published on 2012-10-06T20:20:55Z
Indexed on
2012/10/06
21:40 UTC
Read the original article
Hit count: 300
We've been moving data centers and I have a lot of old records that were not correctly but in DNS as CNAME records, but A records that have a direct IP (e.g. 192.168.100.n) and they're all moving to a new subnet (10.19.100.n).
I just need to write a powershell script to change all those records. I found this site:
http://www.indented.co.uk/index.php/2008/12/30/administering-microsoft-dns-in-powershell/
and from it I made this simple script:
$dnsServer = "meldc2"
$scope = New-Object Management.ManagementScope("\\$dnsServer\root\MicrosoftDNS")
$path = New-Object Management.ManagementPath("MicrosoftDNS_Zone")
$options = New-Object Management.ObjectGetOptions($Null,[System.TimeSpan]::MaxValue, $True)
$ZoneClass= New-Object Management.ManagementClass($scope,$path,$options)
$Zones = Get-WMIObject -Computer $dnsServer -Namespace "root\MicrosoftDNS" -Class "MicrosoftDNS_Zone"
$Zones | Get-Member
foreach($Z in $Zones) {
$Z | Select-Object Name,DsIntegrated,ZoneType,Reverse,Data
}
but that only gets me a listing of root zones. I don't understand how to iterate over all the entries in each of the zones. Also, all the examples I've seen involve adding new zones, but there aren't any examples I can find on modifying existing A records.
© Server Fault or respective owner