Posts Stop Updating Azure Tags Manually
Post
Cancel

Stop Updating Azure Tags Manually

Update Azure Tags with PowerShell

Today, I asked someone to update Azure tags on more than 30 virtual machines based on an Excel spreadsheet.

Two hours later, that person came back to me and said it was finally done. He did it manually.

This is one of those classic examples where automation saves time immediately. Updating tags is important. Tags drive governance, cost tracking, ownership, reporting, and operational consistency. In this particular scenario Tags are used for monitoring, backups, CMDB status etc, so very important. But doing it manually in the Azure portal, one resource at a time, is slow, repetitive, and unnecessarily error-prone. And I was surprised that person who does this at least 2-3 times per month for different set of VMs is still doing it manually. And this does not apply just to tags, but all sorts of repetitive Azure admin work. A lot of these jobs are small, predictable, and ideal for automation.PowerShell is perfect for this kind of work because it lets you take structured input, loop through resources, and apply the same logic consistently in seconds instead of hours.

And today, the barrier is even lower than it used to be. Even if you are not very comfortable with PowerShell or CLI yet, tools like Azure Copilot, AI Shell, and GitHub Copilot Chat in VS Code make it much easier to generate or refine simple automation without leaving your environment. Azure Copilot can even help author scripts and other deployment artifacts in the Azure context, while AI Shell and Copilot Chat let you work conversationally from the command line or editor. 

So instead of clicking through the portal 30 times, you can take a spreadsheet, save it as CSV, run a script, and be done.

Here is a simple script that I wrote and share with that person, that will hopefully save him 2 hours next time.

The script I use reads a CSV file, groups rows by subscription, switches context, finds the target VM, and then applies tags using either of two modes:

  • AddOrReplace: add missing tags and update existing ones when values differ

  • AddOnly: add only missing tags and leave existing tag values unchanged

It expects a CSV with the columns:

  • VMName
  • SubscriptionName
  • RGName
  • and then any number of additional tag columns

Here is a simple example of the CSV format the script expects:

1
2
3
4
5
VMName,SubscriptionName,RGName,Environment,Owner,Application,CostCenter
vm-app-01,Production-Subscription,rg-app-prod,Production,John Smith,ERP,CC1001
vm-app-02,Production-Subscription,rg-app-prod,Production,John Smith,ERP,CC1001
vm-web-01,Shared-Services-Subscription,rg-web-prod,Production,Jane Doe,Portal,CC2004
vm-dev-01,Development-Subscription,rg-dev,Development,Mark Lee,InternalTools,CC3002

Tags not present in the CSV are left unchanged.

I know this example is VM specific, but you can easily adopt this to work with universal Azure Resources.

The nice part is that this pattern is not limited to virtual machines. Once you have the CSV-driven approach, changing it to work with other resource types is usually very easy.

For example, for resource groups, instead of locating a VM with:

1
Get-AzVM -Name $vmName -ResourceGroupName $resourceGroupName

you would use something like:

1
Get-AzResourceGroup -Name $resourceGroupName

And instead of building a VM resource ID like:

1
"/subscriptions/$($subscription.Id)/resourceGroups/$resourceGroupName/providers/Microsoft.Compute/virtualMachines/$vmName"

you would use the resource group’s ID directly:

1
$rg.ResourceId

Then the tagging operation itself can still use the same cmdlet:

1
Update-AzTag -ResourceId $rg.ResourceId -Tag $tagsToMerge -Operation Merge

The same principle applies to many other Azure resources. Usually, all you need to change is the discovery cmdlet and the resource ID you pass into Update-AzTag.

Conclusion

Repetitive Azure work is exactly the kind of work that should be automated. Even a small script can turn hours of clicking into a task that finishes in moments, with better consistency and fewer mistakes. There is really no good reason to do this kind of work manually anymore.

Keep automating and keep clouding around.

Vukasin Terzic

Updated Mar 11, 2026 2026-03-12T02:08:46+01:00
This post is licensed under CC BY 4.0