Restore an enterprise application in Microsoft Entra ID

In this article, you learn how to restore a soft deleted enterprise application in your Microsoft Entra tenant. Soft deleted enterprise applications can be restored from the recycle bin within the first 30 days after their deletion. After the 30-day window, the enterprise application is permanently deleted and can't be restored.

Important

If you deleted an application registration in its home tenant through app registrations in the Microsoft Entra admin center, the enterprise application, which is its corresponding service principal also got deleted. If you restore the deleted application registration through the Microsoft Entra admin center, its corresponding service principal, is also restored. You'll therefore be able to recover the service principal's previous configurations, except its previous policies such as Conditional Access policies, which aren't restored.

Tip

Steps in this article may vary slightly based on the portal you start from.

Prerequisites

To restore an enterprise application, you need:

View restorable enterprise applications

Take the following steps to recover a recently deleted enterprise application. For more information on frequently asked questions about deletion and recovery of applications, see Deleting and recovering applications FAQs.

Important

Make sure you're using the Azure AD PowerShell module. This is important if you've installed both the Azure AD PowerShell module and the AzureADPreview module.

  1. Run the following commands:

    Remove-Module AzureADPreview
    Import-Module AzureAD
    
  2. Connect to Azure AD PowerShell:

    Connect-AzureAD
    
  3. To view the recently deleted enterprise application, run the following command:

    Get-AzureADMSDeletedDirectoryObject -Id <id>
    

Replace ID with the object ID of the service principal that you want to restore.

  1. Run connect-MgGraph -Scopes "Application.ReadWrite.All" and sign in with a Global Administrator user account.

  2. To view the recently deleted enterprise applications, run the following command:

    Get-MgDirectoryDeletedItem -DirectoryObjectId <id>
    

Replace ID with the object ID of the service principal that you want to restore.

View and restore recently deleted enterprise applications using Graph Explorer.

To get the list of deleted enterprise applications in your tenant, run the following query.

GET https://graph.microsoft.com/v1.0/directory/deletedItems/microsoft.graph.servicePrincipal

From the list of deleted service principals generated, record the ID of the enterprise application you want to restore.

Alternatively, if you want to get the specific enterprise application that was deleted, fetch the deleted service principal and filter the results by the client's application ID (appId) property using the following syntax:

https://graph.microsoft.com/v1.0/directory/deletedItems/microsoft.graph.servicePrincipal?$filter=appId eq '{appId}'. Once you've retrieved the object ID of the deleted service principal, proceed to restore it.

Restore an enterprise application

  1. To restore the enterprise application, run the following command:

    Restore-AzureADMSDeletedDirectoryObject -Id <id>
    

Replace ID with the object ID of the service principal that you want to restore.

  1. To restore the enterprise application, run the following command:

    Restore-MgDirectoryObject -DirectoryObjectId <id>
    

Replace ID with the object ID of the service principal that you want to restore.

To restore the enterprise application, run the following query:

POST https://graph.microsoft.com/v1.0/directory/deletedItems/{id}/restore

Replace ID with the object ID of the service principal that you want to restore.

Permanently delete an enterprise application

Warning

Permanently deleting an enterprise application is an irreversible action. Any present configurations on the app will be completely lost. Carefully review the details of the enterprise application to be sure you still want to hard delete it.

To permanently delete a soft deleted enterprise application, run the following command:

Remove-AzureADMSDeletedDirectoryObject -Id <id>
  1. To permanently delete the soft deleted enterprise application, run the following command:

    Remove-MgDirectoryDeletedItem -DirectoryObjectId <id>
    

To permanently delete a soft deleted enterprise application, run the following query in Microsoft Graph explorer

DELETE https://graph.microsoft.com/v1.0/directory/deletedItems/{object-id}

Next steps