Powershell / Azure - Add CNAME Record

202 Views Asked by At

I am trying to create a CNAME record in Azure DNS via Powershell (Actually trying to create a series of records but happy to start with one)

I found the following:

Get-AzDnsRecordSet -Name NAME -RecordType CNAME -ResourceGroupName RESOURCEGROUPNAME -ZoneName domain.com 
| Add-AzDnsRecordConfig -Cname ALIAS 
| Set-AzDnsRecordSet

But, when I use that I get

Get-AzDnsRecordSet: The resource record 'NAME' does not exist in resource group 'RESOURCEGROUPNAME' of subscription 'XXX'.

But, NAME is not a current CNAME record.

I'm trying to get a record that ends up with

NAME CNAME 600 ALIAS

What am I missing and where do I set the TTL value?

1

There are 1 best solutions below

0
On

This did the trick (after some more research)

New-AzDnsRecordSet -Name "NAME" -RecordType CNAME -ZoneName "domain.com" -ResourceGroupName "RESOURCEGROUPNAME" -Ttl 600 -DnsRecords (New-AzDnsRecordConfig -Cname "ALIAS")