New Delhi , Moti Nagar
+91-9007641046
subhendu@subhendumct.com

How to tag 1000+ resources ? Bulk Tagging

Live in Future - Live in Cloud

How to tag 1000+ resources ? Bulk Tagging

Being an architect another job is to define tagging policy if its not there in place . And it’s very simple work to decide what is the best possible way to tag resources if have gone through my last tagging post . Now let’s talk about how to deploy tagging in azure .

 

If you want to overwrite tag on Resource group then follow this script :

"Remember this script will overwrite your exciting tagging "
$ResourceGroupName = "Type Your RG Name"
#it will show your existing Tagging with RG details
Get-AzureRmResourceGroup -ResourceGroupName $ResourceGroupName 
#it will show your existing Tagging 
(Get-AzureRmResourceGroup -ResourceGroupName $ResourceGroupName).Tags
#new Tag
$tags = @{"tag-Global"="All"; "testtag-Program"="IBM"; "Created-By"="Subhendu" }
#Apply
Set-AzureRmResourceGroup -ResourceGroupName $ResourceGroupName -Tag $tags

If you dont want to overwite your exsting tagging , just want to add new tag . Follow the bellow one .

"Remember this script will add this new tags with your exciting tagging "
$ResourceGroupName = "Type Your RG Name"
Get-AzureRmResourceGroup -ResourceGroupName $ResourceGroupName
$tags = (Get-AzureRmResourceGroup -ResourceGroupName $ResourceGroupName).Tags
$tags += @{"Testtag-Global"="All"; "Testtag-Program"=""; "Created-By"="Subhendu" }
Set-AzureRmResourceGroup -ResourceGroupName $ResourceGroupName -Tag $tags

if you want to tag your VM only follw this script :

"Remember this script will overwrite your exciting tagging "
#Type VM Name
$VMName = "Type your VM here"
#To show existing Tag
(Get-AzureRmResource -ResourceName $VMName).Tags
#To store VM RG details in value
$RGName = (Get-AzureRmResource -ResourceName $VMName).ResourceGroupName
#Tag you want to apply
$tags = @{"tag-Global"="All"; "testtag-Program"="IBM"; "Created-By"="Subhendu" }
Set-AzureRMResource -ResourceGroupName $RGName -Name $VMName -ResourceType "Microsoft.Compute/VirtualMachines" -Tag $tags -Force
#it will show you Final Tagging
(Get-AzureRmResource -ResourceName $VMName).Tags

Leave a Reply

Your email address will not be published.