Search code examples
azureazure-powershellazure-cli2

How to delete azure resource using tag?


Is it possible to delete my azure resources(in different resource groups) using tag? If possible, how to achieve it in powershell?

I have searched but found nothing related. Maybe I have missed something basic?

Any guidance will be appreciated.


Solution

  • You could use the below changing the values and piping into the Remove-RmResource command, let me know how you get on!

    I haven't tried this without the RG Name specified but cant see why not, just check the output before the pipe (ie. Find-AzureRmResource -TagName $tagname -TagValue $TagValue)

    $rg= “ResourceGroupName”
    $tagname = “TagName”
    $TagValue =”TagValue”
    Find-AzureRmResource -TagName $tagname -TagValue $TagValue | where{$_.resourcegroupname -eq $rg}| Remove-AzureRmResource -force