How to delete Resource Groups from Azure through PowerShell script

Currently I’m doing the course Data Engineering on Microsoft Azure (DP-203) and from the DP-203-Data-Engineer repository on GitHub we have a PowerShell called dp-203-setup.ps1 that create all resource groups automatically for us on your Azure account with specific types of resources (Storage account, Azure Databricks Service, Synapse workspace, etc).

So, it happened to me that I ran that script on a wrong way, and then I had to delete all of them from my Azure account.

But I do like to work less manually as possible, so I created a PowerShell script that can delete all resources automatically (it may take some time to complete depends on how many resources you have).

How to use them

The first step is to install Azure modules on PowerShell:

Install-Module -Name AzureRM -Force

After that, you can run the first script to delete all resource groups from your Azure account or delete a specific group by simply editing the script.

In order to delete all resources, just uncomment the line where it has the code below.

In order to delete specific recources, leave the code below uncommented. Just remember to replace the resources you have on your Azure account from the ones below (DEMO, DEMO2).

Testing

If you see below, I create one resource on my Azure account called DEMO just to test the script.

So when I run the code below just to check if the resource is there, it’s shows correctly:

Get-AzureRmResourceGroup | Where-Object {$_.ResourceGroupName -in "DEMO"}

And if you run the code to get specific resources group within in a list and delete them from your Azure account without confirmation works as below.

That’s it! I hope you enjoyed this article and the step by step. I encourage you to create a resource on your Azure account as I did, so you can test this script working like a charm! The script of this article can be found on my GitHub repository: guimatheus92/Delete-Resource-Groups-from-Azure-through-PowerShell-script: A PowerShell script that can delete all resources automatically from your Azure account. (github.com)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store