Categories: Uncategorized

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
king

Recent Posts

Create Complex NSG – PowerShell

Creating NSG in azure is easy unless you want to create multiple NSG with multiple…

4 years ago

Restore VM from Recovery Service Vault – PowerShell

# Mention your VM here $VMName = "SubhenduTestVM" # Mention your Stage Storage here $stagestorageaccountname…

4 years ago

Power Of Powershell 2

Hope you are doing great . Current Time is very critical for us . I…

4 years ago

Power of Powershell

Being a part of Microsoft Education I have explored powershell long time back . But…

4 years ago

New Azure Exam is Ready to Launch

Sorry !! But Yes .  Microsoft is about to release new exam in Azure Segment…

4 years ago

DFSR to Azure File Sync | DFS cross domain Migration | Azure File Sync Agent issue and Solution

Migration is always a part of our life and part of this fantastic IT world…

4 years ago