How to update specified tag from a resource

The usage of Tags on Azure resources is a very common and very useful for several reasons that I will not cover on this post. Although in some occasions, if you need to update a Tag from a resource, because either it’s not suitable anymore or you are reaching the limit of the number of Tags allowed by Azure.

In this case the idea is reuse the Tag Shutdown, although with different values for a specific virtual machine

#Get all tags from Resource (VM)

$tags = (Get-AzureRMVM -ResourceName $VMName -ResourceGroupName $ResourceGroup).Tags

#Since this is a hash table, not an array. Update the value for Shutdown.

$tags[‘Shutdown’] = “NewValue”

#Write the hash table back to the resource

$UpdateTag = Set-AzureRmResource -Tag $tags -ResourceName $ServerName -ResourceGroupName $ResourceGroup -ResourceType Microsoft.Compute/virtualMachines


Marcos Nogueira
Azure MVP
Twitter: @mdnoga

Marcos Nogueira

With more than 18 years experience in Datacenter Architectures, Marcos Nogueira is currently working as a Principal Cloud Solution Architect. He is an expert in Private and Hybrid Cloud, with a focus on Microsoft Azure, Virtualization and System Center. He has worked in several industries, including Aerospace, Transportation, Energy, Manufacturing, Financial Services, Government, Health Care, Telecoms, IT Services, and Gas & Oil in different countries and continents. Marcos was a Canadian MVP in System Center Cloud & Datacenter Managenment and he has +14 years as Microsoft Certified, with more than 100+ certifications (MCT, MCSE, and MCITP, among others). Marcos is also certified in VMware, CompTIA and ITIL v3. He assisted Microsoft in the development of workshops and special events on Private & Hybrid Cloud, Azure, System Center, Windows Server, Hyper-V and as a speaker at several Microsoft TechEd/Ignite and communities events around the world.

One Reply to “How to update specified tag from a resource”

Leave a Reply

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