
In this Azure tutorial, we will discuss How To Create Tags In Azure. Along with this, we will also discuss the below topics.
- What Are Azure tags?
- How To Create Azure Tags Using Azure Portal?
- Create tags in Azure using PowerShell
- Create tags in Azure using Azure CLI
Table of Contents
How To Create Tags In Azure
Now, before we discuss the steps to make an Azure tag, Let’s discuss the Overview of the Azure Tag and why to use the Azure tag. etc. Better to check out Azure Tagging Best Practices and Azure Tag Policy before proceeding further.
Azure tagging is an excellent feature from Microsoft that was introduced recently that can help you to logically group your Azure resources and help you to track your resources. It also helps to automate the deployments of the resources and another important feature is this feature helps to provide the visibility of the resource costs that they are liable for.
Azure tags enable the key: value pairs to be created and assigned to the resources in Azure using Azure Portal, PowerShell. Azure CLI, etc.
Along with the Azure resources, you can also use Azure tags to organize the Azure resource groups and the Azure Subscriptions.
Note: Tag names and Tag Values are case-sensitive in nature.
There are multiple ways to create tags in Azure in the Azure Portal. Let’s discuss here, the quick steps to make an Azure tag using Azure Portal, and PowerShell.
How To Create Azure Tags Using Azure Portal
Let’s discuss how to create Azure tags using Azure Portal. Follow the below steps to create or apply the Azure tag.
Step-1: Login to Azure Portal (https://portal.azure.com/)
Step 2: Navigate to the Resource group for which you want to create the Azure tag.
Step-3: On the resource group page, if you can see the Overview tab, See the Tags (Change) option, Now click on the Click here to add tags link to add the tags.

Step-4: You can provide the name and value for the tag like below.

Step-5: You can keep on adding the name and value, if you want more tags and then click on the Save button to save the changes.

You can see here it added the assigned tags successfully without any issues.

Step 6: If you see the Overview tab of the resource group, you can see the tags are displayed.

Step-7: if you want to add a new tag or you want to delete an existing tag you can click on the Change link.
Step-8: Click on the delete icon now to delete a tag and then click on the save button to save the changes.

Assign Tags To Multiple Resources
You can assign tags to multiple resources at a time using Azure Portal.
Select all the lists of resources and then click on the Assign tags button from the top menu.

Add the names and values on the Assign tags window and then click on the Save button.

You can see below it Successfully assigned the tag to all three resources.

View All Resources With A Tag
If you want to view all the tags in Azure Portal.
Search for the Tag in the Azure Portal and click on the Search result Tags.

You can click on each tag below to see the corresponding resources.

Now for example, If you click on the TSINFO: IT you can see it showed me all the resources that belong to this tag.

We can create the Azure tag for the Azure resources using PowerShell.
Basically, there are two PowerShell commands i.e. New-AzTag and Update-AzTag that can be used to create and update the Azure tags for the Azure resources.
As a prerequisite what we need is, you need to have Az. Resources module 1.12.0 or the later version or You can install the Azure PowerShell version 3.6.1 or the later version.
Let’s see an example
$mynewtags = @{"TSINFO"="IT"; "Status"="Startup"}
$resourceDetails = Get-AzResource -Name mynewstoragedemo -ResourceGroup newresgroup
New-AzTag -ResourceId $resourceDetails.id -Tag $mynewtags
If you run the command again with the different tags this time, you will get the new name and value for the tags in Azure.
$mynewtags = @{"TSINFONEW"="ITS"; "Status2"="Startup2"}
$resourceDetails = Get-AzResource -Name mynewstoragedemo -ResourceGroup newresgroup
New-AzTag -ResourceId $resourceDetails.id -Tag $mynewtags
You can use the command Update-AzTag to add tags to the resources that already have tags. You can set the – Operation parameter to Merge
$mynewtags = @{"TSINFONEW"="ITSE"; "Status3"="Startup3"}
$resourceDetails = Get-AzResource -Name mynewstoragedemo -ResourceGroup newresgroup
Update-AzTag -ResourceId $resourceDetails.id -Tag $mynewtags -Operation Merge
You can add the set of Azure tags for Resource Groups using the below cmdlets.
$mynewtags = @{"TSINFONEW"="ITSE"; "Status"="Startup"}
$resourceDetails = Get-AzResourceGroup -Name newresgroup
New-AzTag -ResourceId $resourceDetails.ResourceId -Tag $mynewtags
Same way, you can update the tags for the resource group using the below PowerShell cmdlet.
$mynewtags = @{"TSINFOTECH"="ITS"; "Status01"="Startupnew"}
$resourceDetails = Get-AzResourceGroup -Name newresgroup
Update-AzTag -ResourceId $resourceDetails.ResourceId -Tag $mynewtags
If you want to use a new set of tags for a subscription then you can use the below PowerShell cmdlet.
$mynewtags = @{"NewDept"="ITS"; "Design"="Android"}
$mysubscription = (Get-AzSubscription -SubscriptionName "Mention your Subscription Name").Id
New-AzTag -ResourceId "/subscriptions/$mysubscription" -Tag $mynewtags
Same way, you can update a new set of Azure tags for the subscription using the below PowerShell cmdlet.
$mynewtags = @{"Dept"="HR"}
$mysubscription = (Get-AzSubscription -SubscriptionName "Mention your Subscription Name").Id
Update-AzTag -ResourceId "/subscriptions/$mysubscription" -Tag $mynewtags -Operation Merge
If you want to retrieve the tags for a particular resource, you can use the below PowerShell cmdlet
$resourcedetails = Get-AzResource -Name resourcename -ResourceGroup newresgroup
Get-AzTag -ResourceId $resourcedetails.id
Same way, if you want to retrieve the tags for a resource group then you can use the below PowerShell cmdlet.
$resourcegroupdetails = Get-AzResource -ResourceGroup newresgroup
Get-AzTag -ResourceId $resourcegroupdetails.id
If you want to see the tags for a subscription, you can use the below PowerShell cmdlet
$mysubscription = (Get-AzSubscription -SubscriptionName "Your Subscription name").Id
Get-AzTag -ResourceId "/subscriptions/$mysubscription "
You can use below PowerShell cmdlet below if you want to retrieve resources that have a specific tag name and value
(Get-AzResource -Tag @{ "NewDept"="ITS"}).Name
If you want to get the resources that have a specific tag name with any tag value, you can use the below PowerShell cmdlet.
(Get-AzResource -TagName "Design").Name
If you want to remove a specific tag then you can use the below PowerShell cmdlet
$DeleteTags = @{"TSINFOTECH"="ITS"; "Status01"="Startupnew"}
$resourcedetails = Get-AzResource -Name resourcename -ResourceGroup newresgroup
Update-AzTag -ResourceId $resourcedetails.id -Tag $DeleteTags -Operation Delete
To remove all tags for the subscription, you can use the below PowerShell cmdlet
$mysubscription = (Get-AzSubscription -SubscriptionName "Mention your Subscription Name").Id
Remove-AzTag -ResourceId "/subscriptions/$mysubscription"
This is all about Azure Tags PowerShell. You can use the above PowerShell cmdlets to create the Azure Tags.
We can also use Azure CLI to create Azure tags or apply Azure tags. Let’s see the different Azure CLI scripts to create the Azure tags or apply the Azure tags.
Use the below Azure CLI scripts to overwrite the tags on a resource
az resource tag --tags 'TSinfo=HR' 'Technology=Android' -g newresgroup -n DemoStorage --resource-type "Microsoft.Storage/storageAccounts"
If you want to append a tag to the existing tags on a specific resource, you can use the below Azure CLI script to do this
az resource update --set tags.'Department'='ITS' -g newresgroup -n DemoStorage --resource-type "Microsoft.Storage/storageAccounts"
If you want to overwrite the existing tags on a particular resource group, you can use the below Azure CLI script.
az group update -n newresgroup --tags 'TSinfo=HR' 'Technology=Android'
You can use the below Azure CLI script to append a tag to the existing tags for a resource group.
az group update -n newresgroup --set tags.'Category'='Info'
If you want to retrieve the tags for a particular resource, you can use the below Azure CLI script.
az resource show -n DemoStorage -g newresgroup --resource-type "Microsoft.Storage/storageAccounts" --query tags
If you want to retrieve the existing tags for a specific resource group, you can use the below Azure CLI scripts.
az group show -n newresgroup --query tags
You can use the below Azure CLI script to get all the resources that have a particular name and value
az resource list --tag Technology=Android
This is all about Azure Tags Azure CLI. As explained above, you can use the above Azure CLI scripts for different purposes.
FAQs
Why Use The Azure Tag?
The main intention of using the Azure tags is to organize the resources in the Azure Portal. When you are organizing the resources properly helps you to identify the category that the resources belong to. So basically, Azure tags are the name-value pairs that help to organize the Azure resources in the Azure Portal.
When you have more resources in your Azure Portal, that time really helps you to categorize your Azure Resources. If you will take an example here, Suppose you have 8 Virtual machines (VM) in your Azure Subscription. Of the 8 virtual machines, 2 are under our development environment 2 are for the QA environment and the next 2 belong to our Production environment. So we can tag them as Environment – Development, Environment – QA, or Environment – Production. Now we can easily get the view of each resource coming under the specific environment.
If you will analyze your detailed Azure usage report, you will find the entry for the tags you assigned for your Azure resources.
Now coming back to our main point, to make Azure tag, Well let’s discuss that.
The first thing is you need the Write access to the Azure resource in order to apply the Azure tag for that resource. Make sure you have to write access before trying to create the Azure tag.
What is the purpose of creating tag in Azure service?
Service tags can help you to define different Azure Firewalls, Network access controls, etc. and the interesting part here is, While creating security rules, you can use these service tags instead of IP addresses.
What is Azure Tag Manager
If you want to keep the Azure tags in your whole environment consistent, It is quite difficult to manage the Azure tags consistency manually. Here is the Azure Tag Manager that helps you with this purpose.
Below are a few key points about the Azure Tag Manager
- Helps you with tag consistency throughout Subscriptions and resource groups.
- You can perform Bulk Edit tags, Import, and Export tags easily with the help of the Azure Tag Manager.
- It helps you to reduce the cost.
What is Azure Tags Inheritance
Tags that are applied to your subscription or resource group aren’t directly inherited by your resources. But Azure tag policy helps you to add or replace the provided tag and value from the parent resource group.
Conclusion
Well, here in this article, we discussed, How To Create Azure Tags, What Is Azure tags? and we also discussed, Creating tags in Azure using PowerShell and Azure CLI. Hope you have enjoyed this tutorial !!!