Create a DNS zone with PowerShell in Azure

MVP

 

Hi Azure friends,

I used the PowerShell ISE for this configuration. But you are also very welcome to use Visual Studio Code, just as you wish. Please start with the following steps to begin the deployment (the Hashtags are comments):

 

#The first two lines have nothing to do with the configuration, but make some space below in the blue part of the ISE

Set-Location C:\Temp
Clear-Host

 

#So that you can carry out the configuration, you need the necessary cmdlets, these are contained in the module Az (is the higher-level module from a number of submodules)

Install-Module -Name Az -Force -AllowClobber -Verbose

 

#Log into Azure
Connect-AzAccount

 

#Select the correct subscription

Get-AzContext

Get-AzSubscription

Get-AzSubscription -SubscriptionName "your subscription name" | Select-AzSubscription

#Create the resource group
New-AzResourceGroup -name MyResourceGroup -location "westeurope"

 

#Create a DNS zone
New-AzDnsZone -Name yourdomain.xyz -ResourceGroupName MyResourceGroup

 

#Create a DNS record
New-AzDnsRecordSet -Name www -RecordType A -ZoneName yourdomain.xyz -ResourceGroupName MyResourceGroup -Ttl 3600 -DnsRecords (New-AzDnsRecordConfig -IPv4Address "10.10.10.10")

 

#View records
Get-AzDnsRecordSet -ZoneName yourdomain.xyz -ResourceGroupName MyResourceGroup

 

#Get the list of name servers for your zone
Get-AzDnsRecordSet -ZoneName yourdomain.xyz -ResourceGroupName MyResourceGroup -RecordType ns

 

#Test the name resolution => Open a command prompt
nslookup www.yourdomain.xyz <name server name>

 

Now you have configured an DNS zone and records with the PowerShell in Azure! Congratulations!

 

#Delete all resources (when you no longer need it)
Remove-AzResourceGroup -Name MyResourceGroup -Force

 

I hope this article was useful. Best regards, Tom Wechsler

 

P.S. All scripts (#PowerShell, Azure CLI, #Terraform, #ARM) that I use can be found on github! https://github.com/tomwechsler

0 Replies