Create Update and Delete Tags on Azure Resource

Learn more about how to use tags to organize your Azure resources and management hierarchy. Also learn the cmdlet used to fetch tags from Azure resources.

What is Tag in Azure Resources?

  • You apply tags to your Azure resources, resource groups, and subscriptions to logically organize them into a taxonomy.
  • Each tag consists of a name and a value pair. For example, you can create tag and apply the name “Environment” and the value “Stage” to all the resources in stage. Learn more about Tagging ideas
  • Tag names are case-insensitive: Example: “Environment” or “environment” they are same tag names.
  • Tag values are case-sensitive: Example: “Stage” or “stage” they are different tag values.

Learn more about how to use tags to organize your Azure resources and management hierarchy

Get-AzResource # To fetch  all resources

Apply tags to Azure Resource

Use New-AzTag to apply tag on resource in Azure.

# Create Tag variable
$tags = @{"Dept"="Finance"; "Status"="Normal"}
# Get the resource that you want to appply tag on.
$resource = Get-AzResource -Name "Application Insights Smart Detection" -ResourceGroup AdmissionApplication
# Apply Tag
New-AzTag -ResourceId $resource.id -Tag $tags

View Tag on Azure Resource

Use Get-AzTag cmdlet to view tag on Azure resource. You have to pass the resource Id though. You can also use Get-AzResource cmdlet to view the tags directly under a particular resource.

# Get the resource that you want to view tag on.
$resource = Get-AzResource -Name "Application Insights Smart Detection" -ResourceGroup AdmissionApplicationGet-AzTag -ResourceId $resource.id
# View tags
Get-AzTag -ResourceId $resource.id

Delete Tag on a Azure Resource

To remove specific tags, use Update-AzTag and set -Operation to Delete. Pass in the tags you want to delete.

# Get the resource that you want to view tag on.
$resource = Get-AzResource -Name "Application Insights Smart Detection" -ResourceGroup AdmissionApplication
# View tags
Get-AzTag -ResourceId $resource.id
# Decide which tags to remove
$removeTags = @{"Dept"="Finance"; "Status"="Normal"}
# Delete the tags
Update-AzTag -ResourceId $resource.id -Tag $removeTags -Operation Delete
# Confirm Tags are deleted by fetching them again
Get-AzTag -ResourceId $resource.id

Delete Tag on a Azure Subscription

To remove all tags from your Azure subscription, use the Remove-AzTag command.

# Get subscription by it's name
$subscription = (Get-AzSubscription -SubscriptionName "Example Subscription").Id
# Remove the tags
Remove-AzTag -ResourceId "/subscriptions/$subscription"

Merge Tag

$tags = @{"Location"="Canada"}
# Merge Tag
Update-AzTag -ResourceId $resource.id -Tag $tags -Operation Merge

Replace Tag

$tags = @{"Dept"="Sales"; "Status"="High"}
# Replace tags
Update-AzTag -ResourceId $resource.id -Tag $tags -Operation Replace

Watch the entire videos on Full Stack Master YouTube Channel related to Managing Tags in Azure Resources

Thanks for reading my article till end. I hope you learned something special today. If you enjoyed this article then please share to your friends and if you have suggestions or thoughts to share with me then please write in the comment box.

Become full stack developer 💻

I teach at Fullstack Master. If you want to become Software Developer and grow your carrier as new Software Engineer or Lead Developer/Architect. Consider subscribing to our full stack development training programs. You will learn Angular, RxJS, JavaScript, System Architecture and much more with lots of hands on coding. We have All-Access Monthly membership plans and you will get unlimited access to all of our video courses, slides, download source code & Monthly video calls.

  • Please subscribe to All-Access Membership PRO plan to access current and future angular, node.js and related courses.
  • Please subscribe to All-Access Membership ELITE plan to get everything from PRO plan. Additionally, you will get access to a monthly live Q&A video call with Rupesh and you can ask doubts/questions and get more help, tips and tricks.

Your bright future is awaiting for you so visit today FullstackMaster and allow me to help you to board on your dream software company as a new Software Developer, Architect or Lead Engineer role.

💖 Say 👋 to me!
Rupesh Tiwari
Founder of Fullstack Master
Email: rupesh.tiwari.info@gmail.com
Website: RupeshTiwari.com

--

--

--

I am a Senior Software Architect, mentor & successful PluralSight Author, professionally I am an expert at Angular, Express, Node.JS, Object Oriented Design but with a particular focus on Service Oriented Architecture, DDD, MEAN stack and Asp.Net.

Recommended from Medium

I am getting cheaper pricing for hosting from other providers. Why is your price high?

New Year’s Resolutions for Software Professionals

pytest - First Flight

Meet the community driven Anitya Platform

Reduce Cost and Increase Productivity with Value Added IT Services from buzinessware — {link} -

PyBlog — Project Structure

IAM Patterns

How to Install the Cassandra PHP Extension on macOS 10.13 High Sierra and 10.14 Mojave

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rupesh Kumar Tiwari

Rupesh Kumar Tiwari

Pluralsight Author, Developer and Trainer. I help students and professionals to become Full Stack Software Developer in less than a Year.

More from Medium

Create Update and Delete Tags on Azure Resource

Azure Cosmos DB — Using PowerShell for bulk deletes and inserts

Microsoft Azure AZ 400 Designing and Implementing Microsoft DevOps Solutions Part 5

Microsoft Azure AZ 400 Designing and Implementing Microsoft DevOps Solutions Exam Dumps

How to access custom attributes from Azure AD-B2C using Graph API(s)