Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
How to remove all empty Resource Groups in an Azure subscription.
October 22, 2015
Q. How can I remove all empty Resource Groups in an Azure subscription?
A. You may create resources and a Resource Group is automatically created which are left behind if you delete the resource. Below is some easy PowerShell to delete any Resource Group that is empty. It displays each Resource Group and the number of resources within.
Switch-AzureMode -Name AzureResourceManager$RGs = Get-AzureResourceGroupforeach($RG in $RGs){ $Resources = Get-AzureResource -ResourceGroupName $RG.ResourceGroupName -OutputObjectFormat New $outputstr = $RG.ResourceGroupName + " - " + $Resources.Length Write-Output $outputstr if($Resources.Length -eq 0) { Remove-AzureResourceGroup -Name $RG.ResourceGroupName }}
You May Also Like