
How to add tags to an Azure virtual machine
- Maxime Hiez
- Azure , Tutorial
- 24 Jan, 2025
Definition
Tags in Azure are customizable labels (in the form of metadata) that you can apply to your resources to organize and manage your cloud environments more efficiently. They play a crucial role in cost management, governance, and task automation.
Prerequisites
Licenses required
- An Azure subscription.
Azure resources
- A deployed virtual machine.
Administrator role
- An account with the Contributor or Owner role on the Azure subscription.
Step 1 : Sign in to the Microsoft Azure portal
Sign in to the Microsoft Azure portal by opening your web browser to https://portal.azure.com.
Step 2 : Add the tags
In the search bar at the top of the screen, type Virtual machines, and click the proposed menu.
All your virtual machines will be displayed; in my case, there is only one (an SBC for telephony).
Click the virtual machine to which you want to apply your tags.
In the left menu, click Tags, manually enter the name and value of each tag in the form and click Apply.
Once validated, they will be visible after a few seconds.
Configuration in PowerShell
You can also add tags via the following PowerShell commands :
$TagsToApply = @{"Environment" = "Telephony"; "Device" = "SBC"; "OS" = "Linux Rocky 8.8"; "Vendor" = "Audiocodes"}
$VirtualMachineName = "vm-sbcteams01"
$RgSbcName = "rg-sbc01"
$Resource = Get-AzResource -Name $VirtualMachineName -ResourceGroup $RgSbcName
New-AzTag -ResourceId $Resource.id -Tag $TagsToApply
Get-AzVM -Name $VirtualMachineName | Select -ExpandProperty Tags
Where to see the result ?
In the search bar at the top of the screen, type Subscritption, and click the proposed menu. If you have several, click the subscription of your choice.
It is possible to track the consumption of your resources in Azure using tags. Note that it is possible to put it on almost all Azure resources (public IPs, network interfaces of virtual machines, resource groups, etc.) which allows for more precise results.
Conclusion
You now know how to add tags to a virtual machine in Azure.
Sources
Microsoft Learn - Add tags via the web
Microsoft Learn - Add tags via the PowerShell
Did you enjoy this post ? If you have any questions, comments or suggestions, please feel free to send me a message from the contact form.
Don’t forget to follow us and share this post.