DEV Community

Wriju's Blog
Wriju's Blog

Posted on

Azure PowerShell : Delete all resource groups by pattern

If you have set of resource groups created for a project which contains a specific string in their name (say the project code). Then it is very easy to delete them all in a single statement.

To get all the resource groups having rg-delete- as prefix

Get-AzResourceGroup -Name "rg-delete-*"
Enter fullscreen mode Exit fullscreen mode

After you confirm they are the right set of names then you can delete them all by

Get-AzResourceGroup -Name "rg-delete-*" | Remove-AzResourceGroup -Force -AsJob
Enter fullscreen mode Exit fullscreen mode

You need to use -Force to avoid any user prompt.

Top comments (0)