How to delete your Office 365 Admin Account

How to delete your Office 365 Admin Account

I have had an Office 365 account for a while that had services like Microsoft Teams and Azure however I no longer needed this. To delete the account you have to follow multiple steps. Use this link https://docs.microsoft.com/en-us/microsoft-365/commerce/close-your-account?view=o365-worldwide

The issue was however in step 5, Delete Tenant. I could not delete my tenant because I had some service principles still present and these mounted to the hundreds for some reason.  So I went off on a search to find out if there was a script that could list all the service principles and then delete them. Below are the steps to run in powershell and this will enable you to delete all your service principles in one go.

  1. Install-Module -Name Az
  2. Use Az Login to authenticate your account
  3. Call  Get-AzADServicePrincipal and copy and paste all the Ids
  4. Remove the name, we just want the ID and NOT the AppID
  5. In VS Code, in the text file, press shift + alt and left click and drag down. This will let you add text to multiple lines. Prepend "Remove-AzADServicePrincipal -ObjectId ". You should have something that looks like the below (I had 125 lines but just copied 3 for an example)                                                           Remove-AzADServicePrincipal -ObjectId 00a606a7-bc4a-4cbe-96c3-e981e43dc99b
    Remove-AzADServicePrincipal -ObjectId 00a99a44-ad2d-4878-9501-e370f406ea11
    Remove-AzADServicePrincipal -ObjectId 018b84cd-85e2-4cfc-951e-73d05180390f
  6. Copy and paste the whole list into the powershell window and watch the command be executed one by one.

Now go back to AzureAD and try to delete the tenant and it should work. It may take a few minutes to refresh however.