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 *

You May Also Like…

Toggen builds a new website

So I have built and hosted a new website for Roger Clark Pest Management they are a family owned and operated Pest...


Just downloaded WizTree (not a sponsor) from It seems to do what it says on the tin which is...

Scam call from “Telstra”

Just had a call from a man with a sub-continental accent from caller ID 0734946596 Told me there was problem with my...