Reputation: 37
Im want to delete the tags from large number of VM in microsoft azure. But I get this error : Can not remove tag/tag value because it's being referenced by other resources. What I need to do and how to fix this error???
Remove-AzureRmTag -Name "sada"
This code i have used to remove sada from all my Azure Virtual Machines
Upvotes: 0
Views: 2254
Reputation: 679
You cannot delete a tag or value that is currently applied to a resource or resource group. Before using Remove-AzTag, use the Tag parameter of the Set-AzResourceGroup cmdlet to delete the tag or values from the resource or resource group. https://learn.microsoft.com/en-us/powershell/module/az.resources/remove-aztag?view=azps-4.8.0#description
The Solution is simple:
Update-AzTag -ResourceId $resource.id -Tag $removeTags -Operation Delete
Upvotes: 0
Reputation: 72151
this means this tag is being used by some resource in azure, you can only remove unused tags with this cmdlet. so your only option is to remove all those tags from existing resource (you can use a fairly simple powershell script for that, or just mass tagging from the portal). and then you can run this cmdlet.
something like this:
$res = Get-AzResource -ErrorAction SilentlyContinue
$res.ForEach{
if ( $_.tags.ContainsKey('sada') ) {
$_.tags.Remove('sada')
}
$_ | Set-AzResource -Tags $_.tags
}
Upvotes: 3