Search This Blog

Tuesday 10 September 2019

Azure Cloudshell powershell for Azure Resource tagging

Force tag onto all resources in an Azure ResourceGroup.  Useful for cost tracking.

CAUTION - overwrites existing tags on resource.

foreach ($r in (Get-AzResource -ResourceGroupName YOUR_RG_NAME)){ Set-AzResource -Tag @{myTag="MyValue"} -ResourceId $r.ResourceId -Force }




UPDATE : remove tag while leaving other intact

Get-AzResource -TagName "MyTagKey" | % {
   $_.Tags.Remove("MyTagKey")
   $_.Tags
   Set-AzResource -ResourceId $_.ResourceId -Tag $_.Tags -Force
}

No comments:

Post a Comment