Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A script to create a new CName on an existing zone in Azure. You can use this script in an Azure DevOps pipeline using a service account with the proper permissions.
# Subscription ID
[Parameter(Position=0, Mandatory=$true)]
# DNS Resource Group Name
[Parameter(Position=1, Mandatory=$true)]
# DNS Zone Name
[Parameter(Position=2, Mandatory=$true)]
# CName Record Name
[Parameter(Position=3, Mandatory=$true)]
# Value CName Record Points To
[Parameter(Position=4, Mandatory=$true)]
#If the Azure AZ module is not loaded, load it.
if(-not (Get-Module Az)) {
Install-Module -Name Az -AllowClobber -Scope CurrentUser -SkipPublisherCheck
#Set Azure Context
Set-AzContext -SubscriptionId $subId
#Get the record set to see if it already exists and if not, create it
New-AzDnsRecordSet -Name $cnameName -RecordType CNAME -ZoneName $zoneName -ResourceGroupName $resourceGroup -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -Cname $cnameValue) -Overwrite -Confirm:$False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment