Open In App

Microsoft Azure – Update Resource Group Tags using PowerShell Script

Last Updated : 03 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Pre-requisite: Azure, Microsoft Azure: Resource Tagging and Best Practices

Here In this article, we will show you how to update tags on existing resource groups using Azure PowerShell script. For this operation will be using Azure Cloud Shell to perform this action. Most importantly to update azure resource group tags one should have an Owner or Contributor Access or User Access administrator role on the target Azure Resource Group to make the changes. No additional modules are required as we are performing this activity on azure cloud shell.

Implementation Steps:

Step 1: Log in to Azure Portal.

Step 2: Navigate to Cloud Shell and Access it.

Step 3: After accessing you should switch to PowerShell Console.

Step 4: Now, Create a PowerShell file named updateRGroupTags.ps1 using the below command.

touch updateRGroupTags.ps1

Step 5: Use the following command to add the code in updateRGroupTags.ps1 PowerShell file.

code updateRGroupTags.ps1
powershell

 

Step 6:- Copy and paste the below PowerShell script in updateRGroupTags.ps1 and update the tags list according to your needs to make changes on the existing azure resource group.

## Parameteres
$RGroupName = "<Add resource group name"

## Add/Modify Tags of your Choice
$ResourceGroupTags = @{
"Environment" = "PROD"; 
"SystemCriticality" = "HIGH";
"BusinessOwner" = "Mike Aron";
"BusinessOwnerEmail" = "abc@xyz.com";
"CostCenter" = "XYZ";
"SupportTeam" = "XYZ"
}

$RGroup = Get-AzResourceGroup 
-Name $RGroupName
Update-AzTag -ResourceId 
$RGroup.ResourceId -Tag 
$ResourceGroupTags -Operation Merge
updateRGroupTags

 

Step 7:- After modifying the changes in the script. Run the file updateRGroupTags.ps1 using the below command. 

./updateRGroupTags.ps1
run the script

 

Now, move to Azure Portal and check the update tags on the Resource group.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads