How to Delete App Registrations and Enterprise Applications from Microsoft Azure Active Directories Using PowerShell

Recently, I needed to delete an Azure Active Directory that I had created for learning and training purposes. I had used it primarily to create virtual machines, which I had deleted as I finished my learning. However, what I did not remember was that I had used the same Active Directory previously to experiment with creating Apps. So, when I tried to delete the Active Directory, I did not see check marks for the following:

  1. Users
  2. App Registrations
  3. Enterprise Applications

Deleting users was easy. I simply went to the Users section and deleted them. But when I went to Enterprise Applications and App Registrations sections to do the same, I saw nothing there. They were both empty. The following explains how to delete these two areas if they do not appear in the Portal UI:

Deleting Enterprise Applications

It appears that what you can’t see from the Portal UI, you must figure out how to deal with using PowerShell. As the name suggests, PowerShell is a powerful tool that interacts with Azure. Use the following steps:  

  1. Run PowerShell as Administrator.
  2. Enter the Connect-AzureAD command and log in with your Azure AD Global Administrator account.
  3. Enter Get-AzureADServicePrincipal to display all registered Enterprise Applications along with their ObjectIds.

  1. For each record found, run following command:  

Remove-AzureADServicePrincipal -objectid <ObjectId from above>

If you prefer, you can find and delete all Enterprise Applications using the following script:

$ObjectIds = (Get-AzureADServicePrincipal).ObjectId
For ($i=0; $i -lt $ObjectIds.Length; $i++)
             Remove-AzureADServicePrincipal -objectid $ObjectIds[$i]

NOTE: If you receive the following error for any of the above, simply continue. Basically, the error states that it won’t let you delete Microsoft internal app:

Deleting App Registrations   

To delete all App Registrations, log in again, but this time as an Azure RM Account. You can use the same global admin account:

  1. Run the Login-AzureRMAccount command and log in again using your global admin account.
  2. Enter Get-AzureRmADApplication to get a list of all App Registrations.

  1. Run Remove-AzureRmADApplication -objectid <ObjectId from above> for each App Registration found in your Azure Active Directory, making sure you enter “Y” to confirm that you want to delete it.

Again, if you prefer, you can use the script below to find and delete all App Registrations in one shot:

$ObjectIds = (Get-AzureRmADApplication).ObjectId
For ($i=0; $i -lt $ObjectIds.Length; $i++)
            Remove-AzureRmADApplication -objectid $ObjectIds[$i]

That’s it! Now you are ready to go back to the Azure Portal and delete the Active Directory.

If you have any questions regarding Azure, Azure Active Directory, or PowerShell, contact the experts at AKA Enterprise Solutions. Interested in other Cloud services? AKA’s Cloud Experts are ready to help! Check out our Azure Cloud Service offerings.

By | 2018-06-18T19:49:55+00:00 June 18th, 2018|Cloud (Azure), Tech Tips|0 Comments
Alternative Text

Contributor: Ahmad Pirani

Ahmad Pirani Senior Consultant on the Delivery team. As the lead developer on CRM projects, is a highly skilled technical resource with deep development knowledge and CRM best practices.

Leave A Comment