I like my blog posts to be informative, but I also like them to feel personal. So, in honour of The Fantastic Four: First Steps releasing that week, I thought it was a good moment to write about my own first steps in Azure automation.
The task was practical enough: I needed to register the Microsoft.Maintenance resource provider across every subscription in my tenant so Azure Update Manager maintenance schedules could be deployed consistently.
Doing that manually in the Azure portal would have been slow, repetitive, and easy to get wrong.
Why Automate Tasks Like This?
When you are dealing with dozens or even hundreds of subscriptions, manual work stops being reasonable very quickly.
Automation helps because it:
- Saves time
- Applies the same logic everywhere
- Reduces the chance of missing a subscription
- Makes the process reusable next time
In this case, a short PowerShell script using Azure CLI turned a potentially tedious portal task into something I could complete in minutes.
My Thought Process
When I need to automate something in Azure, I usually start by working backwards from the manual process.
I ask myself two questions:
- How would I do this in the portal?
- Which CLI commands represent those same steps?
From there, the script came together in three simple stages.
My Approach
First, get the enabled subscriptions in the tenant and store the resource provider name in a variable so the script stays reusable:
$subs = az account list --query "[?state=='Enabled'].id" -o tsv
$providerToRegister = "Microsoft.Maintenance"
Next, loop through each subscription and inspect the provider registration state:
foreach ($sub in $subs) {
$provider = az provider show --namespace $providerToRegister --subscription $sub | ConvertFrom-Json -Depth 32
}
Finally, if the provider is not already registered, register it:
foreach ($sub in $subs) {
$provider = az provider show --namespace $providerToRegister --subscription $sub | ConvertFrom-Json -Depth 32
if ($provider.registrationState -ne "Registered") {
Write-Host "Registering provider $providerToRegister for subscription $sub"
az provider register --namespace $providerToRegister --subscription $sub | Out-Null
}
else {
Write-Host "Provider $providerToRegister already registered for subscription $sub"
}
}
That was it. Every subscription was checked, and anything missing the provider was fixed automatically.
Learn First, Script Second
Microsoft Learn is usually my first stop when I am trying to automate something in Azure. In this case, the documentation on registering resource providers with Azure CLI gave me exactly what I needed to get moving.
I tend to prefer Azure CLI over Azure PowerShell for tasks like this. Both are valid, but I find CLI commands a little easier to read and reason about. Something like az deployment group create feels more literal to me than the PowerShell equivalent.
That is just preference, but the principle is useful: pick the tooling that helps you think clearly.
A Quick Reflection
This was a simple example, but that is exactly why it matters. A lot of Azure automation starts with small, repetitive tasks that are obvious candidates for scripting once you step back and break them into pieces.
The more often you do that, the more natural automation becomes.
And if you have GitHub Copilot helping you build or refine the script, that journey gets even faster.
