Tuesday, 21 June 2016

How to delete Azure Active Directories that won't delete

As a result of studying for Azure certfications I'd created several Active Directories under my MS Azure subscription. Wanting to clean these up, I attempted to delete these from within the classic portal, only to be greeted with the following message:
 
 
Directory contains one or more applications that were added by a user or administrator.
Clicking through to the applications menu I expected to be able to delete the offending applications. No such options exists, therefore I had a google and found this blog post.

There are a couple of tricks here:

  1. Create a new user with global admin in the active directory (you must delete this later as users also prevent deletion of the Active Directory)
  2. Install the Azure Active Directory PowerShell module
  3. Connect to the active directory using Connect-MsolService and the account you just created
  4. Run Get-MsolServicePrincipal | Remove-MsolServicePrincipal to delete all applications (that can be... expect some errors)
I then deleted the new admin user I created in step 1 and retried the Active Directory delete, hey presto, worked for me.

Hope this helps.