Use it or lose it: Removing all Azure resources from your subscription

If you’re a Microsoft Azure user, you probably know how to create Azure resources. But what about if you want to delete Azure resources? A customer of mine was using a subscription for testing purposes, and after a while of inactivity, he realized that there were some costs on having resources hanging around, and his goal was to delete all Azure resources from the subscription.

To do this, we can always use the portal: click on All Resources or Resource Groups and start selecting and deleting the resources. That is doable if you have a small number of resources, but when you need to delete hundreds of objects in a given subscription, PowerShell becomes a more appropriate tool for the job.

Azure resources

So, we had to get a brief glimpse of what we had in that subscription, list the resources, and delete them. Since I had to enter all the PowerShell cmdlets above, I thought would be nice to share the few cmdlets required to perform this activity.

The first cmdlet is to list by group and location (it is up to you how you want to group the output), the idea is to list the number of resources per type.

Get-AZResource | Group-Object ResourceType,Location | fl

We can also list all the resources by running Get-AZResource cmdlet.

To remove all resources, we can run the following cmdlet.

Important note: You are removing all resources in your subscription! Make sure that you are in the right subscription and triple-check if those resources can be removed before running this cmdlet!

Get-AzResource | ForEach { Remove-AzResource -ResourceId $_.ResourceId -Force -Confirm:$False }

Featured image: Pixabay

Leave a Comment

Your email address will not be published.

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

Scroll to Top