Open In App

How to Update Azure Subscription Tags using PowerShell?

Pre-requisite: Azure

Updating Azure subscription tags using PowerShell is a straightforward process that allows you to easily manage and organize resources in your subscription. With PowerShell, you can add, modify, or remove tags from individual resources or apply tags to multiple resources simultaneously. This can help you to better track and manage resources, set cost center allocations, and provide more detailed reporting on your usage. PowerShell provides a flexible and efficient way to automate this process, making it easy to keep your subscription tags up-to-date and relevant.



Steps to Update Azure Subscription Tags using Azure PowerShell:

Step 1: Log in to the Azure portal

Step 2: Open the Azure Cloud Shell and switch to PowerShell



Step 3: Create a new file using the following command

touch updateAzSubTags.ps1

 

Step 4: Use the following command to write code in the updateAzSubTags.ps1 file

code updateAzSubTags.ps1

Now add the below-following code in the update in the file and modify the Tag Name and Tag Value fields of your choice.

#Switch to Default Azure Subscription
$SubId = "<add subscriptionID here>"
Set-AzContext -Subscription "$SubId"

#Add the required tags here
$NewTags = @{
"BusinessArea" = "Finance";
"ITTeam" = "GIT";
"ChargebackTo" = "GIT";
"DataType" = "Internal";
"Environment" = "Production";
"SystemCriticality" = "Critical";

}

#Update Tags on Subscription 
Update-AzTag -ResourceId "/subscriptions/$SubId" -Tag $NewTags -Operation Merge

 

Step 5: Once you are done updating the code use the below command to execute the file.

./updateAzSubTags.ps1

 

Step 6: Now Validate the Tags of the Azure Subscriptions. 

Steps to Validate the Azure Subscription Tags in Azure Portal:

Step 1: Log in to the Azure portal 

Step 2: Navigate to Subscriptions from azure global search

Step 3:  Select the subscription which has update tags for.

Step 4: Click on “Tags” in the left-hand menu and verify the update of the tags. 

 

Article Tags :