2

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.

3 Answers3

4

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
James Donovan
  • 336
  • 1
  • 5
1

Answer of @James does work, but I got prompt in PS Find-AzureRmResource will be deprecated in upcoming breaking release. (Probably I came back too late(2 months after he posted) and happen to meet this update.)

So I recommend to use Get-AzureRmResource with AzureRM 6.8.1.

0
$rg= “<Resource group name>”
$tagname = “<Tag name Ex: Env>”
$TagValue =”<Tag Value Ex: Dev>”
Get-AzResource -TagName $tagname -TagValue $TagValue | where{$_.resourcegroupname -eq $rg}| Remove-AzResource -force