Azure: delete all Tags

76404357 1 Reputation point
2022-07-06T09:34:29.75+00:00

Hello

I have script to delete all Tags.

$RGs = Get-AzResourceGroup
foreach ($RG in $RGs){

Set-AzResourceGroup -Name $RG.name -Tag @{}  

}

$removeTags = @()
$resources = Get-AzResource
foreach ($resource in $resources) {

Update-AzTag -ResourceId $resource.id -Tag $removeTags   

}

I get Tags yet:

Get-AzTag

Name Count
---- -----
displayName 2
App 1
Department 1
Env 1
Owner 1

I can't find which resource is attached.

Get-AzResource

<no results>

Any idea?

thanks

Azure Resource Mover
Azure Resource Mover
An Azure service used for moving multiple resources between Azure regions.
232 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,521 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Andreas Baumgarten 108.8K Reputation points MVP
    2022-07-06T19:07:26.68+00:00

    Hi @22308421 ,

    why are you not using Remove-AzTag?
    https://video2.skills-academy.com/en-us/powershell/module/az.resources/remove-aztag?view=azps-8.1.0

    Not tested by myself!

    Remove-AzTag -Name "Department" -PassThru  
    Remove-AzTag -Name "App" -PassThru  
    Remove-AzTag -Name "Env" -PassThru  
    Remove-AzTag -Name "Owner" -PassThru  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


  2. Andreas Baumgarten 108.8K Reputation points MVP
    2022-07-07T17:36:02.587+00:00

    Hi @22308421 ,

    please try this and see if it helps:

    $value = "Owner"  
    (Get-AzResource -TagName $value)  
    (Get-AzResourceGroup -Tag @{($value) = '' })  
    

    It looks like the Tag details in the different object types/cmdlets are not consistent. For Get-AzResource it's -TagName for Get-AzResourceGroup it's -Tag.

    The easiest way to see the related resource of a Tags is via Azure Portal:

    218697-image.png

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.