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 ataxonomy
. - 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.
Rupesh Tiwari
Founder of Fullstack Master
Email: rupesh.tiwari.info@gmail.com
Website: RupeshTiwari.com
Comments