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.
Open PowerShell and install the Az
module using the cmdlet below.
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
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 Account
, SubscriptionName
, TenantId
, and Environment
.
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"
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.
Free Resources