I am new to PowerShell, but have written some basic scripts over the years. I mainly work in Unix/Linux so am very familiar with shell, perl, python, etc scripting. I am looking to write some PowerShell scripts to update DNS records, mainly updating IP addresses.
PS Version
5.1.14393.3471
In searching around I have found a few examples but so far I have not succeeded. I’m trying to do something simple like this:
Get-DnsServerResourceRecord -ZoneName example.com -RRType A
$new = $old = Get-DnsServerResourceRecord -ZoneName example.com -Name test
$new.RecordData.IPv4Address = [System.Net.IPAddress]::parse('10.10.1.10')
Set-DnsServerResourceRecord -NewInputObject $new -OldInputObject $old -ZoneName example.com
Get-DnsServerResourceRecord -ZoneName example.com -RRType A
Which errors out with
HostName RecordType Type Timestamp TimeToLive RecordData
-------- ---------- ---- --------- ---------- ----------
test A 1 0 01:00:00 10.12.1.10
Set-DnsServerResourceRecord : Resource record in OldInputObject not found in example.com zone on Server1 server.
At C:\scripts\dnstest.ps1:15 char:1
+ Set-DnsServerResourceRecord -NewInputObject $new -OldInputObject $old ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Server1:root/Microsoft/...rResourceRecord) [Set-DnsServerResourceRecord], CimException
+ FullyQualifiedErrorId : WIN32 9714,Set-DnsServerResourceRecord
test A 1 0 01:00:00 10.12.1.10
Can anyone shed some light on how this can be done? Any guidance is greatly appreciated..
Thanks,
HB