Share via


How to tag a VM using the Azure CLI

Applies to: ✔️ Linux VMs ✔️ Windows VMs ✔️ Flexible scale sets ✔️ Uniform scale sets

This article describes how to tag a VM using the Azure CLI. Tags are user-defined key/value pairs which can be placed directly on a resource or a resource group. Azure currently supports up to 50 tags per resource and resource group. Tags may be placed on a resource at the time of creation or added to an existing resource. You can also tag a virtual machine using Azure PowerShell.

You can view all properties for a given VM, including the tags, using az vm show.

az vm show --resource-group myResourceGroup --name myVM --query tags

To add a new VM tag through the Azure CLI, you can use the azure vm update command along with the tag parameter --set:

az vm update \
    --resource-group myResourceGroup \
    --name myVM \
    --set tags.myNewTagName1=myNewTagValue1 tags.myNewTagName2=myNewTagValue2

To remove tags, you can use the --remove parameter in the azure vm update command.

az vm update \
   --resource-group myResourceGroup \
   --name myVM \
   --remove tags.myNewTagName1

Now that we have applied tags to our resources Azure CLI and the Portal, let's take a look at the usage details to see the tags in the billing portal.

Next steps