How to Create Resource Groups With Tags in Azure?

PowerShell Script to Create Resource Groups With Tags in Azure

This article show you about how to automate Creating and Updating Azure Resource Group with Tags Names and Values using Azure PowerShell Script. Before going forwarding let's check some important FAQs that you should know about Azure Tags.

What are Tags in Azure?

Tags are Key value pair which can be applied on azure resources. They help in organizing, managing, tracking and identifying resources based on applied tag names and values.

What are Tags used for in Azure?

Simple answer for this is "Tags are used to organize Azure resources and also to manage and track cost of resources based on tag and it's value".

How many Tags can a resource have?

A maximum of 15 Tags can be applied on resources.

How many Tags can be assigned to a Resource Group in Azure?

A maximum of 15 tags can be applied on a Resource Group.

Does all Azure Resources Support Tags?

The answer is "No". Not all azure resource supports tags. You can apply tags only to some resource types in Azure.

Create a New Resource Group in Azure with Tags:

Use the below Azure PowerShell Script to Create Resource Group by giving Tag Names and Values.

## Add Deployment Parameters
$Subscription = "_add_Subscription_name_" 
$RGName = "_add_resourceGroup_name_"
$RGLocation = "_add_resourceGroup_location_"

## Switch to Azure Subscription
Set-AzContext -SubscriptionName "$Subscription"

## Modify or Add More Tags
$RGTags = @{"BusinessArea" = "RANDD"; "ITTeam" = "AI DEV"; "Environment" = "DEV"; "SystemCriticality" = "LOW"}

## Create Azure Resource Group with Tags Name and Values
New-AzResourceGroup -Name $RGName -Location $RGLocation -Tag $RGTags

Update Azure Resource Group Tags:

Use the below PowerShell Script to Update Resource Group Tag Names and Values.

## Add the Parameters
$Subscription = "_add_Subscription_name_" 
$RGName = "_add_resourceGroup_name_"
$RGLocation = "_add_resourceGroup_location_"

## Switch to Azure Subscription
Set-AzContext -SubscriptionName "$Subscription"

## Store Azure Resource Group Details to $RG Variable
$RG=Get-AzResourceGroup -Name "$RGName"

## Modify or Add More Tags
$RGTags = @{"BusinessArea" = "RANDD"; "ITTeam" = "AI TEST"; "Environment" = "TEST"; "SystemCriticality" = "LOW"}

## Update and Merge Azure Resource Group Tags Name and Values
Update-AzTag -ResourceId $RG.ResourceId -Tag $RGTags -Operation Merge