How to delete Resource Groups from Azure through PowerShell script

Guilherme Matheus
3 min readOct 6, 2021
Photo by Ulisses on UlyssesNeves

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.

Image by Author

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"}
Image by Author

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.

Image by Author

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)

--

--

Guilherme Matheus

Mechanical Engineer Business Intelligence developer, passionate about technology, I have knowledge and experience to create a BI architecture and much more 📚.