Created
April 29, 2019 18:43
-
-
Save jasongaylord/1ee3a1060cfcbcabe133f315d08fbfb1 to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[CmdletBinding()] | |
# Subscription ID | |
[Parameter(Position=0, Mandatory=$true)] | |
[string]$subId, | |
# DNS Resource Group Name | |
[Parameter(Position=1, Mandatory=$true)] | |
[string]$resourceGroup, | |
# DNS Zone Name | |
[Parameter(Position=2, Mandatory=$true)] | |
[string]$zoneName, | |
# CName Record Name | |
[Parameter(Position=3, Mandatory=$true)] | |
[string]$cnameName, | |
# Value CName Record Points To | |
[Parameter(Position=4, Mandatory=$true)] | |
[string]$cnameValue | |
) | |
#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