Cascading Resource Group Tags in Azure

Resource Manager Policies in Azure are the way to define and enforce a tagging system.
You can define in a json format rules that must be adhered to for new resources that are deployed.
eg.

For resources that you’ve already created, you’ll need to decide on the appropriate strategy. One that I’ve recently put together is a script that cascades the tags you define at the Resource Group level down to the individual resources (VM’s, vNETs, etc etc).

It doesn’t override any of the existing tags that a resource has, simply ensuring that each of the resources has at a minimum the tags that are defined at the Resource Group level.

This version isn’t optimised for running on a schedule in Azure Automation as it’s not a powershell workflow so doesn’t parallelise the foreach loops.

For the latest version, use the GitHub link.
https://github.com/Gordonby/PowershellSnippets/blob/master/Add-ResourceGroupTagsToResources.ps1

2 thoughts on “Cascading Resource Group Tags in Azure”

  1. Hey Gordon, lovely script but I’ve noticed an issue with it and was hoping perhaps you had some insight. It appears that the compare-object on line 52 is failing, as it’s receiving $rgTagKeys as being Null. As a result, your script is applying tags to a resource that starts with no tags just fine, but it is failing to append tags that exist on the RG but do not exist on the resource itself. Any ideas on a quick fix?

Leave a Reply

Your email address will not be published. Required fields are marked *