Reputation: 133
I'm trying to update a bunch of dns cname entry, using azure-powershell.
I have no troubles getting the dns entry I need to update, but my problem starts when trying to update the cname (due to the fact there can be only one cname entry).
I went to azure documentation, and found about set-azdnsrecordset, but I failed to find the correct parameter/syntax to update the CNAME
Here is what I tried.
$rs = Get-AzDnsRecordSet -name "test1" -RecordType CNAME -ZoneName "zone.io" -ResourceGroupName "dns"
$rs.Records[0].Records = "new-test-v1.com"
Set-AzDnsRecordSet -RecordSet $rs
With error on $rs.Records[0].Records = "new-test-v1.com":
The property 'Records' cannot be found on this object. Verify that the property exists and can be set.
echo $rs
Id : /subscriptions/[redacted]/resourceGroups/[redacted]/providers/Microsoft.Network/dnszones/[redacted].io/CNAME/test1
Name : test1
ZoneName : zone.io
ResourceGroupName : dns
Ttl : 3600
Etag : [redacted]
RecordType : CNAME
TargetResourceId :
Records : {test-v1.com}
Metadata :
ProvisioningState : Succeeded
PS : I did found a working solution. Deleting/recreating the records works fine enough. I also realise that if something goes wrong in the creation segment, I lose my record (setting failsafe would be a lot of additional work), So I keep it as a last ressort.
Upvotes: 1
Views: 947
Reputation: 133
Climbing on AjayKumarGhose-MT shoulders (mention of -Cname $rs.Records.cname) , I did found the solution I needed to use
$rs.Records[0].cname = "new-test-v1.com"
instead of
$rs.Records[0].Records = "new-test-v1.com"
Full solution is then :
$rs = Get-AzDnsRecordSet -name "test1" -RecordType CNAME -ZoneName "zone.io" -ResourceGroupName "dns"
$rs.Records[0].Records = "new-test-v1.com"
Set-AzDnsRecordSet -RecordSet $rs
Upvotes: 1
Reputation: 4893
One of the workaround to update CNAME records in Azure DNS
To update CNAME we have to remove the existing alias and then have to add a new one.
We have tried with below cmdlt
and updated the CNAME:
PowerShell Cmd:-
$rs = Get-AzDnsRecordSet -name "rahul" -RecordType CNAME -ZoneName "zone.com" -ResourceGroupName "rgname"
Remove-AzDnsRecordConfig -RecordSet $rs -Cname $rs.Records.cname | Set-AzDnsRecordSet
$newcname = "new-test-v1.com"
Get-AzDnsRecordSet -name "rahul" -RecordType CNAME -ZoneName "myzone.com" -ResourceGroupName "rgname" | Add-AzDnsRecordConfig -Cname $newcname | Set-AzDnsRecordSet
Upvotes: 2