I am writing an script that would get all the resources in a resource group and removed them and then it removes the resource group itself in an azurestack environment. I couldn't just use
$Resources = Find-AzureRmResource -ResourceGroupName $ResourceGroupName
foreach ($resource in $Resources)
{
Remove-AzureRmResource -ResourceGroupName $ResourceGroupName -ResourceName $resource .Name -ResourceType $resource.ResourceType -Force
}
because if I have Offers in my resource group and that offer has subscriptions in it, then I cannot remove the Offer before removing the all the subscriptions in it. My Question is: is there a way to get each resource $A in a resource group $RG and all the dependent resources $D for that resource $A and delete them?
There can be so many types of resources in a resource group, and I am not sure what are the other resources beside "offers" that could have dependent items which would have to be removed first before the resource can be removed. for example, what if my resource group has Virtual machines in it, is there network adapters that need to be removed first?
what is the hierarchy for removing resources in a resource group and how are they depended on each other.( I wish there was a dependents attribute for each resource in Azurestack so you could see what are the things that needs to be removed in order to be able to remove that item.