Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


How to apply a tag to the Azure Resource Group using PowerShell

Gutha Vamsi Krishna


Azure Resource Group is a logical group of resources that includes virtual machines, databases, web applications, and storage accounts.

Generally, we create tags to identify to which department or cost center it belongs in Azure. We can create and apply a tag to a resource group using the New-AzTag cmdlet.


New-AzTag -ResourceId "resource group id" -Tag "tags as a dictionary"

We'll follow the steps below to apply a tag to a Resource Group.

Step 1

Open PowerShell and install the Az module using the cmdlet below.

Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force

Step 2

Log in to the account with the following command.

It will provide a link that can be opened in the browser, where we enter the code that has been provided.

Connect-AzAccount -UseDeviceAuthentication

After a successful log in, it will print AccountSubscriptionNameTenantId, and Environment.

Step 3

Since we need a resource ID to create a tag, we get the instance of the Resource Group using the command below.

$resourceGroup = Get-AzResourceGroup -Name "provide your resource group name here"

Step 4

Now create a tag and apply it to a Resource Group using the following command.

Here we'll create a tag and name it Department=Sales.

New-AZTag -ResourceId $resourceGroup.ResourceId -Tag @{Department="Sales"}

Connect to the terminal below and execute the commands discussed above.

Terminal 1




Gutha Vamsi Krishna
Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring