Delete your resource groups in parallel using the az group command


Donovan Brown posted a How to on this earlier this year, I wanted to see if it was possible to do it using the az group command.  This is what I finally came up with.

I downloaded and installed the latest PowerShell Core for Windows from GitHub releases.  I picked the latest preview V7.0.0-preview.1 release and installed the Az module as per the steps here.

The commands I executed were as follows:

az login
az account set –subscription “<The name of your subscription> “
az group list –query “[].{name:name}” –output table | foreach-object {start-job -InputObject $_ -ScriptBlock {az group delete –yes –name “$input” }}

start-job az group delete

then sat back and watched all the resource groups slowly disappear from the Azure portal for the subscription I was trying to clean-up.

Note: The first two jobs that launch actually fail because the first two rows are the title of the column and the separator from the table output format.

You do not need to install PowerShell to make this work, you can always launch a Cloud Shell directly in the Azure portal in your browser or from the Azure mobile app and run your PowerShell commands from there as shown below:

A bit more work than Donovan’s method but possible nonetheless.  Maybe I should have tried the TSV output format??  If you have any comments let me know below.

About Wes MacDonald

Wes MacDonald is a DevOps Consultant for LIKE 10 INC., a DevOps consulting firm providing premium support, guidance and services for Azure, Microsoft 365 and Azure DevOps.

No comments yet... Be the first to leave a reply!

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.