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) {
0{
Write-Host "Yes"
Get-AzResourceGroup | Remove-AzResourceGroup -Force -Verbose -AsJob
}1{
Write-Host "No"
}2{
Write-Host "Cancel"
}
}
0 Comments