Delete All Resources Inside an Azure Resource Group PowerShell

In this blog post, we will use the Az PowerShell module for Azure to delete all resources inside a resource group without deleting the actual resource group.

In many use cases, you might have a situation where you use the same resource group to test things and keep redeploying workloads and deleting them. I know that I have a resource group that I use all the time to deploy test resources that I delete as soon as I finish the testing.

In some cases, organisations give administrators, engineers and developers access to a resource group where they can deploy workloads for testing and other purposes and if the resource group gets deleted the permissions need to reassign which can take time.

This post will show you how to use the Az PowerShell module, which works on Windows, Linux and macOS, to delete all the resource inside a resource group without deleting the resource group.

Check Resources

Before we delete the resource inside our resource group lets first check the resource group and all the resource that it holds using the following cmdlet.

Get-AzResource -ResourceGroupName deploycontainers

The following command is using the get-azresources with the actual resource group name that we would like to delete all its resources and we are piping the results to the remove-azresources cmdlet which deletes all the resources.

The -Force switch is used to bypass the prompts to delete each resource. If you don’t use the force switch, you will get a prompt for each resource that will get deleted.

Get-AzResource -ResourceGroupName deploycontainers | Remove-AzResource -Force

To validate that all the resources have been deleted run the following cmdlet

Get-AzResource -ResourceGroupName deploycontainers