Remove all your resource groups and hence their contents in Azure

Written by James McDonald

September 25, 2019

You can do this two ways either with one line of power shell code or more safely by wrapping it in a script that first checks which subscription you are logged into and then ask you nicely if you really want to delete all the resource groups in your Subscription.

How to unsafely clean up after you have done a heap of testing in your Azure account

Get-AzResourceGroup | Remove-AzResourceGroup -Force -Verbose -AsJob

How to less unsafely clean up after you have done a heap of testing in your Azure account

## The following four lines only need to be declared once in your script.
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes","Deletes all resource groups."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No","Exit without doing anything."
# $cancel = New-Object System.Management.Automation.Host.ChoiceDescription "&Cancel","Description."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$subscription = Get-AzSubscription
## Use the following each time your want to prompt the use
$title = "Warning: All Azure Resource Groups will be removed from:
`t Account: `"$($subscription.ExtendedProperties.Account)`"
`t Subscription: `"$($subscription.Name)`""
$message = "Are you sure you want to do this?"
$result = $host.ui.PromptForChoice($title, $message, $options, 1)
switch ($result) {
    Write-Host "Yes"
    Get-AzResourceGroup | Remove-AzResourceGroup -Force -Verbose -AsJob
    Write-Host "No"
  Write-Host "Cancel"


Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Meraki Open Source Licenses

Until today I assumed that Meraki was built in-house with only closed source software. But having a look at the...


If you have Veeam backup failing with the Updating BCD failed with Cannot update SafeBoot flag and SentinelOne is...