Update DNS IP Address from CSV

I made a script to update DNS records from a CSV. There are a couple of other topics that touch the issue on this forum…

https://powershell.org/forums/topic/updating-dns-records/
and
https://powershell.org/forums/topic/basic-dns-record-a-creation-script/

The second one had some posts with some errors that I was seeing with my script, but I was able to suss out what I was doing wrong from the second comments from “Don Jones”. Anyway, I figured out I needed to look up the IP in the CSV in a strange way, for reasons I don’t quite understand. With CSV headers of “Computer,IP”.

 

Import-Module DNSServer
$zoneName = “DNS.zone”
$DNSServer = “dnsserver.dns.zone”
Import-CSV C:\dns\Records.csv | %{
$new = Get-DnsServerResourceRecord -ComputerName $DNSServer -ZoneName $zoneName -Name $.“Computer”
$old = Get-DnsServerResourceRecord -ComputerName $DNSServer -ZoneName $zoneName -Name $
.“Computer”
$new.recorddata.ipv4address=[System.Net.IPAddress]::parse($($_.“IP”))
Set-DnsServerResourceRecord -NewInputObject $new -OldInputObject $old -ComputerName $DNSServer -ZoneName $zoneName
}

Having to use ($($_.“IP”)) to get the IP from the CSV resolved the errors and made everything work as expected. Hope this helps someone else.