This post, shows, how to use Azure PowerShell to add tags to an Azure Resource.

  • Tags are metadata that you can add to an Azure resource.
  • You can tag resources with name/value pairs to organize and group resources in your subscription.
  • Each resource or resource group can have a maximum of 15 tag name/value pairs.

Az PowerShell Workaround

If you want to know how to install the PowerShell Az module on your machine, check out this link.

The simplest way to get started is to sign in interactively at the command line.

If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task we will use the following commands:

Once you set your default subscription, you are ready to add tags to your Azure Resources.

List all tags and their number of occurrences in your Azure subscription using PowerShell

You can view all tags and their number of occurrences in your subscription using the Get-AzTag cmdlet. The Count property shows how many times the tag has been applied to resources and resource groups in your subscription.

Get-Aztag

Add tags to an Azure Resources

To add a Tag to a Resource Group with Azure PowerShell, use the Set-AzResourceGroup cmdlet with the following syntax:

Set-AzResourceGroup

To add a Tag to a Resource (Virtual Machines, Virtual Networks, etc ) with Azure PowerShell, use the Set-AzResourceGroup cmdlet with the following syntax:

Set-AzResource

Retrieve existing resource tags

If you want to obtain all tags applied to a Resource group. you should use the Get-AzResourceGroup cmdlet with the following syntax:

Get-AzResourceGroup

If you want to obtain all tags applied to an Azure Resource. you should use the Get-AzResourceGroup cmdlet with the following syntax:

Get-AzResource

Add new tags to existing tags

If you apply tags to a resource or resource group, overwrite existing tags in that resource or resource group. For this reason, we must use different methods to add tags to the resource or resource group that already has tags applied.

To add a tag to a resource group that has existing tags, use :

Set-AzResourceGroup

To add a tag to an Azure resource that has existing tags, use :

You can also use the following method to add new tags to an Azure resource.

Tags Azure PowerShell

Remove all tags

To remove all the labels of an Azure resource, pass an empty hash table. Here we remove all tags from a resources group.

Tags Azure PowerShell

And here we remove all tags from an Azure resource

Tags Azure PowerShell

If you want to know more about tags in Azure, check out this link: https://docs.microsoft.com/en-us/rest/api/resources/tags