Restore Deleted Objects Using Microsoft Entra PowerShell

Restore Deleted Objects Using Microsoft Entra PowerShell

Accidentally deleting a critical user account, application registration, or group in Microsoft Entra ID tenant can trigger a moment of panic. But fear not! Microsoft 365 deleted objects are not immediately gone forever. Microsoft Entra ID has a soft-delete mechanism, giving admins a 30-day window to restore them. Only after this period, the object is permanently deleted and cannot be restored.

You can manage object deletions in Microsoft 365 through the Entra admin center, but for faster, and bulk recovery, PowerShell is the superior choice. Let’s learn how to restore deleted objects using Microsoft Entra PowerShell now!

Pre-requisites to Retain Deleted Objects in Microsoft Entra

Let’s make sure you have everything needed to successfully run the recovery commands. Your Microsoft Entra ID account must have one of these administrator roles:

  • To restore users: User Administrator
  • To restore groups: Groups Administrator
  • To restore applications: Application Administrator, Cloud Application Administrator, or Hybrid Identity Administrator
  • To restore administrative units: Privileged Role Administrator

If you’re unsure about your permissions, a Global Administrator has the rights to perform all these actions. However, Global Administrator is a high-privileged account, and it is recommended to follow least privileged access practices and use role-specific administrators whenever possible.

How to Recover Deleted Data Using Microsoft Entra PowerShell

Firstly, connect to the Microsoft Entra PowerShell module and assign scopes based on action:

  • Restore Users: User.ReadWrite.All
  • Restore Groups: Group.ReadWrite.All
  • Restore Applications: Application.ReadWrite.All
  • Restore Administrative Units: AdministrativeUnit.ReadWrite.All

Once the appropriate scopes are assigned, you can proceed to restore the deleted objects safely. Now, let’s see how to

  1. Restore a recently deleted user
  2. Bulk restore deleted users
  3. Restore a deleted Microsoft 365 group
  4. Bulk recover deleted Microsoft 365 groups
  5. Restore a recently deleted application
  6. Bulk restore application registration
  7. Recover a deleted service principal
  8. Bulk Restore Entra ID service principals
  9. Recover soft-deleted administrative units
  10. Bulk restore administrative units

1. Restore a Recently Deleted User in Microsoft 365

Deleting a user account in Entra doesn’t immediately erase it. Instead, the user account remains suspended for a month, giving admins time to reverse the action.

Find the deleted users in the organization by running the following cmdlet.

The result shows the user ID along with the deleted date and time. You will need the Object ID to restore a user.

Then restore the deleted user by executing the below cmdlet:

Replace <UserId> with the actual Object ID of the user to be restored.

When restoring a user, their previous licenses are reapplied. If your tenant doesn’t have available licenses, this may temporarily place you out of compliance.

2. Bulk Restore Deleted Users in Microsoft Entra ID

In large organizations, accidental deletions can affect multiple users at once during system migrations, HR data corrections, or automated account cleanup processes. In such cases, restoring them one by one is time-consuming. Instead, you can import a CSV file with Users ID and restore them in bulk using PowerShell.

Input CSV file format:

Bulk Restore Users in Entra

3. Restore a Deleted Microsoft 365 Group

Groups play a central role in collaboration by providing shared access to resources such as Teams, SharePoint, and Outlook. Accidentally deleting a group in Microsoft 365 can disrupt access for many users. To restore a group in Microsoft 365, follow the steps below.

Use the following cmdlet to view groups currently in the soft-deleted state:

This retrieves all deleted group IDs that are eligible for recovery. The output will show details such as display name, object ID, and group type.

Once you’ve identified the group, use its Id to restore it using:

Replace the ID with the deleted group’s ID you want to restore.

Important: Only Unified Groups (Microsoft 365 Groups) can be restored. It is not possible to restore deleted distribution lists and security groups in Microsoft 365.

4. Bulk Restore Deleted Microsoft 365 Groups

This method is perfect for bulk recovery scenarios where several Microsoft 365 groups are lost simultaneously due to accidental deletion or administrative mistakes. Bulk restoration helps maintain business continuity and minimizes downtime for affected teams.

Replace <FilePath>.csv with the complete file path to your CSV.

Input CSV file format:

Bulk Restore Groups in Entra

5. Restore a Soft Deleted Enterprise Application

The restoration of applications requires a clear understanding of the application object model in Microsoft Entra ID. An application is represented by two distinct objects:

  • Entra ID application registration – Defines the application’s identity and configuration.
  • Service Principal – Represents the instance of the application in a specific tenant.

When an application is deleted, both objects are soft-deleted and must be restored individually.

Firstly, to find the list of deleted application registrations, run the following.

This will list details such as application name, ID, and publisher domain.

With application ID from the command above, restore the deleted applications you wish to in Entra ID.

After restoring the application, you might also need to restore deleted application’s service principal which is detailed below.

6. Bulk Restore Application Registrations in Microsoft 365

For development or testing environments where many app registrations might be deleted, restoring them one-by-one is impractical. This bulk approach lets you restore Entra app registrations in one go.

Specify your CSV file path instead of <FilePath>.csv.

Input CSV file format:

Bulk Restore App Registrations in Entra

7. Recover a Deleted Service Principal in Entra ID

Find the deleted service principals in the organization by running the below:

Once you identify the required object, you can restore it with the Restore-EntraDeletedDirectoryObject cmdlet, specifying the unique Object ID of the service principal.

Replace <ServicePrincipalIdObjectId> with the actual ID of the service principal you wish to restore.

Note: If you restore only the service principal without restoring the associated app registration, the service principal becomes unusable. It loses its link to the application metadata like client secrets, permissions, and redirect URIs, making authentication and access to resources fail. For complete Entra app functionality, you need to restore both the deleted app registration and service principal together.

8. Restore Entra ID Service Principals in Bulk

You can restore multiple service principals in bulk using a CSV file. Ensure your CSV file has a column named ServicePrincipalId.

Use this approach to quickly restore multiple deleted service principals without manually restoring each one.

Input CSV file format:

Bulk Restore Service Principals in Entra

9. Recover Soft-Deleted Administrative Units in Entra ID

Administrative units in Entra ID are containers used to delegate administrative permissions and apply policies to a subset of users or groups. Their accidental deletion can disrupt governance models. The Get-EntraDeletedAdministrativeUnit cmdlet provides a view into all soft-deleted administrative units.

Replace <AdministrativeUnitId> with the actual ID of the administrative unit you wish to restore in the organization.

10. Bulk Restore Administrative Units in Microsoft 365

In large organizations, losing multiple administrative units can halt delegated administration for entire departments. This bulk restoration script quickly recovers all your administrative units, their memberships, and scoped role assignments in one go.

Modify <FilePath>.csv with the correct path where your CSV is stored.

Input CSV file format:

Bulk Restore Administrative Units in Entra

Pro tip: To prevent permanent deletions of Microsoft 365 objects, consider enabling protected actions in Entra ID.

Now you know how to quickly restore deleted users, groups, apps, and more in Microsoft 365. Feel free to reach us through the comment section, if you have any queries.

Restore Deleted Objects Using Microsoft Entra PowerShell

by Praba time to read: 6 min
0