Create tags on Azure (Azure Cloud Shell)

Hi again

This post it’s to demonstrate how to create the Azure Tags on a Resource Group as well as on an Azure Resource (stogare account) using PowerShell using Azure Cloud Shell.

You need the Azure Resource ID from the Azure Resoure Group you’re applying the changes (adding tags)

The following command will add the following tags to the Azure Resource Group “RG-TOR-DEVTEST-BI

tag name: Department
tag value:IT
tag name:Environment
tag value:Devtest

TIP! – change the “$thisrgid” variable from “12345678-ab12-b9ab-az01-s390-123456789asd” to your Azure Resource Group ID

$tags = @{"Department"="IT"; "Environment"="Devtest"}
$Resources = Get-AzResource | where-object { $_.resourcegroupname -eq "RG-TOR-DEVTEST-BI"}
$thisrgid = "/subscriptions/12345678-ab12-b9ab-az01-s390-123456789asd/resourceGroups/RG-TOR-DEVTEST-BI"
New-AzTag -ResourceId $thisrgid -Tag $tags

Log on Azure portal https://portal.azure.com

Launch the Azure Cloud shell

Copy and paste the PowerShell command(s) on the Azure Cloud Shell screen and hit enter.

Check the results using Azure Portal

TIP! –Ā Use the following command to retrieve all azure tags on your subscription.

#list your Azure Subscriptions
get-azsubscription



#set your current Azure Subscription 
Set-AzContext -SubscriptionName "Disaster Recovery (DR)"

#list all tags on current environment / subscription
az group list --query [].tags

Reference

https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/tag-resources

thanks,

Thiago Beier
TwitterLinkedInFacebookRSS