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

Overview

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.

Syntax

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
Terminal
Loading...
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved