# Deleting an Azure AD Tenant

Earlier last week I had a need to delete an Azure AD tenant, and this turned out to be a much more difficult task than I had originally anticipated so I thought I would document the steps I went through in case others encounter the same problems.

If your syncing your on-prem AD up to Azure AD you need to disable this from inside the Azure Portal so that it disconnects your users from the sync, otherwise you cannot delete your synced users.

Update: It seems it is no longer possible to disable AAD Sync from the portal, so instead this needs to be done with PowerShell. You will need to install the  two modules described in step 2.

• Once these are installed, open up PowerShell and run Connect-MsolService

• Once you are signed in you can run Set-MsolDirSyncEnabled –EnableDirSync \$false

• This will disable the directory sync.

• You can check this using this command:(Get-MSOLCompanyInformation).DirectorySynchronizationEnabled

### 2. Remove Applications

You want to do this step before deleting users, you will see why in a moment.

The first step is to delete applications from inside the portal, that is fairly straight forward, just select the app and delete it. However if this was all you did you would get an error when trying to delete the tenant that applications still exist. There are likely to be some hidden applications that need to be deleted using PowerShell.
This is where the need for a user account comes in, you will need a global admin that is hosted in that tenant, so not a live account of account from another directory. You will also need the Microsoft Online Services Sign-In Assistant for IT Professionals RTW and Azure Active Directory Module for Windows PowerShell tools installed.

• Once these are installed, open up PowerShell and run Connect-MsolService

• Once you are signed in you can run Get-MsolServicePrincipal | Select DisplayName To see the list of applications in the tenant

• Finally run Get-MsolServicePrincipal | Remove-MsolServicePrincipal to delete these applications.

You will get some errors on applications it cannot delete, that is fine, it will delete the ones that need to be deleted.

### 3. Remove Users

At this point you can now go ahead and delete any users in the domain, aside for your account which you will use to delete this tenant (and obviously can’t originate from this tenant). If you can’t delete any users from AD sync go back to step 1 and make sure it is disconnected.

### 4. Remove Custom Domains

If you have setup any custom domain names for the tenant go ahead and remove these now.

### 5. Remove Subscriptions

This is where the pain really started for me. If you have any subscriptions in your tenant (Azure AD basic or premium, office 365 etc.) then you need to remove these, and you can’t do it your self. If you have AD Premium/Basic you need to raise a ticket either with your volume licence re-seller, or with the office 365 billing team if you paid via credit card or are on a trial, do not raise a ticket in the Azure portal, they can’t help.

This took me a few days to get things moving and get codes to remove the subscriptions, then it took a further 72 hours for them actually to get removed, so not a quick process.

### 6. Remove Tenant

At this point you should now be able to remove the tenant through the portal. If you get any errors at this point you’ll need to run back over the steps here to make sure you removed everything. You can also take a look at this KB article.