resource cleanup which are only tagged to specific tag

72 views Asked by At

I am using the below AZ script to delete the tag for a resource. But I want only specific tag needs to be deleted not all the tags that are associated with resource. Example There is tag name "Business unit" value 101, below are the resource name which are inside this tag: hrm01vm, hrmvnet, hrmappservice The above resource are also associated with other tags as well like "Department" & "supportedby"

az tag delete --resourceid --yes -y

This deletes the entire tags which are associated with the resource. I want only "Businessunit" tags to be deleted. Any command that I need to include?

Parameters in PS.

1

There are 1 answers

0
SwethaKandikonda On

After reproducing from my end, I could able to achieve this using Remove("<Key>"). Below is the complete script that worked for me.

$a = Get-AzResource -ResourceGroupName <RESOURCE_GROUP> -Name <FUNCTION_APP>
$a.Tags.Remove("<YOUR_REQUIRED_TAG>")
$a | Set-AzResource -Force

RESULTS:

enter image description here

After execution

enter image description here