question

MarlisSeptian-3433 avatar image
1 Vote"
MarlisSeptian-3433 asked WilliamMyers-5768 commented

Can't Delete Azure Active Directory

Hi Guys,

So I want to delete my azure AD lab environment, but everytime I want to delete the directory it's say that i need to delete all of my enterprise application. But, there are not any enterprise application listed.

When I create global admin user, the status of enterprise application is checked and now of course the Users status is uncheck cause there are still user in it.

Take a look at my screenshoot below.

  • Enterprise Application status in uncheck
    4051-b.png

  • There are no enterprise application
    4061-c.png

  • Now user is uncheck
    3954-asd.png

*Note : Why I'm creating the user again is cause I want to delete the enterprise application via power shell, but when I create the user the status for my enterprise application is check (means there are no application)


azure-active-directoryazure-ad-domain-services
b.png (15.0 KiB)
c.png (15.2 KiB)
asd.png (13.8 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

soumi-MSFT avatar image
0 Votes"
soumi-MSFT answered WilliamMyers-5768 commented

MarlisSeptian-3433, Make sure you dont have any Enterprise apps or Users in your tenant [Except the Global Admin of that tenant]. If there are any other user left in the directory apart from the Global Admin, this Status would come up and you will have to delete your user in AAD first, before deleting the Directory, or you will get a message saying you cannot delete the directory, because you have one or more users.

Try refreshing the page or navigate to the AAD home page and the get back to the delete Directory page and this time the check for directory deletion should pass and you would be able to see the "Delete" button at the end of screen.

Also, if you would want to delete the Applications under Enterprise Apps section using Powershell, you can try to follow the steps below:

  1. Go to https://www.powershellgallery.com/packages/AzureAD/ to get the latest powershell Azure AD module

  2. Start Powershell and run:
    Install-Module -Name AzureAD

  3. Once done run:
    Connect-AzureAD

  4. You will be prompted to login, login with the user you created and will be asked to change your password:

  5. You should now be able to list all the current application SPs in a directory:
    Get-AzureADServicePrincipal


  6. Now, delete all non-required apps in the tenant directory, for me it was the Microsoft Visual Studio Team Services.
    Remove-AzureADServicePrincipal -objectid [enter object id here]

Hope this helps and do let us know if this helps and if there are any more queries around this, please do let us know so that we can help you further. Also, please do not forget to accept the response as "Answer"; if the above response helped in answering your query.














· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

As you can see from my second screenshoot. I dont have any enterprise application, however the status for my enterprise application is still uncheck (look at my first screenshot).

0 Votes 0 ·

Wow! Thank you! Your advice solved my problem! I was trying to delete my .onmicrosoft.com(the directory) today too and it always ask me to delete my enterprise applications. Then I found this question and your answer. After login through the powershell and delete all the unneeded apps I finally delete my onmicrosoft.com directory! Cheers! (I'm even not a programmer and only know some basic knowledge of C++!)
Thank you for your easy-to-understand answer! Really helps!

0 Votes 0 ·

Thank you, I expanded on your steps slightly and took a kill it with fire approach.

foreach ($SP in (Get-AzureADServicePrincipal)){Remove-AzureADServicePrincipal -ObjectID $SP.ObjectID}

0 Votes 0 ·
MarlisSeptian-3433 avatar image
0 Votes"
MarlisSeptian-3433 answered

Any solution guys?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

soumi-MSFT avatar image
0 Votes"
soumi-MSFT answered soumi-MSFT commented

@MarlisSeptian-3433, The reason its not showing the Enterprise Apps with check mark is may be there are some entries remaining in the Tenant for the service principals and thats what is not allowing the deletion of the tenant. I would suggest you to trying using the Steps mentioned for powershell and try to see if for that tenant, if any Service Principals gets listed.
You can try to following steps to list all the service principals in your tenant:

  1. Go to https://www.powershellgallery.com/packages/AzureAD/ to get the latest powershell Azure AD module

  2. Start Powershell and run: Install-Module -Name AzureAD

  3. Once done run: Connect-AzureAD

  4. You will be prompted to login, login with the user.

  5. You should now be able to list all the current application SPs in a directory: Get-AzureADServicePrincipal

  6. Now, delete all non-required apps in the tenant directory, for me it was the Microsoft Visual Studio Team Services. Remove-AzureADServicePrincipal -objectid [enter object id here]

You can also refer to the following doc: https://docs.microsoft.com/en-us/archive/blogs/kennethteo/deleting-azure-ad-tenant



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MarlisSeptian-3433, Also, I would in case from Powershell also no service principal gets listed, then I would suggest you engage the support team of Microsoft, so that they can investigate this in detail.

Do let us know if you can create a case with the us so that we can help you further, if not, then do let us know so that we can get a one time case created for you to help you on this.

0 Votes 0 ·
MarlisSeptian-3433 avatar image
0 Votes"
MarlisSeptian-3433 answered soumi-MSFT commented

Hi @soumi-MSFT
I already try that but there's no service principal listed.
I'll be very grateful if you can create the case for me, since I dont have support subscription.

Thanks

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MarlisSeptian-3433, I apologize for missing out on this. For me to create a one time free case, I would request you to please share the following details on azcommunity[at]microsoft[dot]com:

  1. Tenant Name/Tenant ID:

  2. Subscription ID: This is must as based on your subscription ID we would be able to create a case for you.

When you send the details in the email, make sure you provide the reference for this thread's URL.

0 Votes 0 ·
microsoftgov1834mrssmith-1627 avatar image
0 Votes"
microsoftgov1834mrssmith-1627 answered

Contact specialist for help it's difficult

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TomCox-0503 avatar image
0 Votes"
TomCox-0503 answered

Have you tried 'long path tool'?
it's very helpful for me.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ARC avatar image
2 Votes"
ARC answered

What was the resolution to this problem? I am facing exactly the same situation.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

$$ANON_USER$$ avatar image
2 Votes"
$$ANON_USER$$ answered ArthurAugsten commented

Had this same issue. My solution for me was as explained by @soumi-MSFT - there are service principals which seem to get added to the tenant which block deletion. I logged into the Az PoSH module and issued the command Get-AzADServicePrincipal and you see them here.

Problem is, some of these are not removable and give error: "Remove-AzADServicePrincipal: Specified App Principal ID is Microsoft Internal"

The way I got around this was just to use: Get-AzADServicePrincipal | select Id | Remove-AzADServicePrincipal

  • this removed everything which could be removed. Now the 'Enterprise Applications' check passed okay and the 'Delete' button appeared. Just another warning, when I tried straight away I got error 'Unable to delete tenant' with no detail - but after about 2-4 minutes, I tried again and it deleted.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks so much for this! I was able to remove the remaining enterprise apps that showed in the portal using remove-azadserviceprincipal and the objectIDs but the Delete button still wasn't showing for tenant. I then used Get-AzADServicePrincipal | select Id | Remove-AzADServicePrincipal as you instructed and it removed all of the remaining apps. Once that completed the delete button showed and I was able to delete my tenant.

0 Votes 0 ·

Thanks so much for this. Worked like a charm using Notepad ++

  1. Obtained all ObjectIds by running Get-AzADServicePrincipal

  2. Copied the output to Notepad ++

  3. Appended the command Remove-AzADServicePrincipal in front of each object ID
    For example, Remove-AzureADServicePrincipal -ObjectId f3bf74c2-bccc-44e6-bec8-428ceb5aa024

  4. Copied / Pasted each command into PowerShell in groups of 10 or less to be sure every command was processed as expected

Originally, I tried copying all 95 lines into PowerShell and it just didn't run through them all. I could tell because, it didn't return 95 response codes.

0 Votes 0 ·

I had the same issue and your solution solved my problem! Thanks.

0 Votes 0 ·
IainAitken-3428 avatar image
2 Votes"
IainAitken-3428 answered KnutEGjerdsbakk-5509 commented

Tip for anyone doing this - I had 105 items listed as Principals.

If you have this:

  • Run the command Get-AzureADServicePrincipal as above

  • Copy the entire list from powershell by highlighting and ctrl+c

  • Paste into an excel sheet (Column A in excel)

  • In the next row (Column B) enter the formula: =LEFT(A1,FIND(" ",A1)-1) This deletes everything in the row after the first space, leaving just the object Ids.

  • Drag formula down to cover all rows

  • in the next row (Column C) enter the formula: =PROPER("Remove-AzureADServicePrincipal -objectid "&B1) This adds in the comand to delete them to the same line.

  • Drag formula down to cover all rows.

  • copy all of Column C and past into word as plain text so that it is not in a table.

  • Copy the entire word doc useing ctrl+A then ctrl_C

  • Right click in Powershell to paste. It will then work through deleting them all and show an error on the ones that cannot be deleted.

Go back to your delete tenant page and delete.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

This saved my day! Thank you!!!

0 Votes 0 ·