Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Azure / How to Restore Deleted Users in Azure AD (Microsoft 365)

June 8, 2023 AzureMicrosoft 365PowerShell

How to Restore Deleted Users in Azure AD (Microsoft 365)

When you delete a user account in Azure (Microsoft 365), the user is not deleted immediately. The disabled user account is stored in AAD for 30 days. In this article, we’ll look at how to restore a deleted user in Azure AD (AAD) using Azure Portal or PowerShell.

In Azure AD, there are two modes for deleting objects (users):

  • Soft delete – a user is deleted from the active tenant users and the user account is suspended (moved to the AAD recycle bin). At the same time, all user attributes (including M365 group membership, assigned access permissions to Exchange Online mailboxes and folders, calendar permissions, Teams chats, etc.) remain unchanged. Azure services will automatically delete such an account after 30 days;
  • Hard delete (permanent) – an object is deleted from the Azure Recycle Bin and cannot be restored using the built-in tools (you may force delete any object from Azure AD without waiting 30 days).

To delete or restore users, a Global administrator or User administrator role must be assigned to your account.

The easiest way to restore a deleted user in AAD is to use the Azure Portal:

  1. You can find a list of deleted users available to restore in the Azure AD admin center (https://aad.portal.azure.com/);
  2. Go to Users and select Deleted Users. There is a list of deleted users that includes the date when the user was deleted (Deletion date) and the date when the user will be permanently removed from AAD (Permanent deletion date);
  3. Find a user you want to restore (you can search a user by the User principal name or add other user attributes as filters), select it and click Restore user; Restore deleted users in Azure AD Portal
    Note that when you delete a user, the user’s userPrincipalName attributes change. If earlier it was [email protected], for example, after you delete the user the object ID in AAD is added to the beginning: [email protected]
  4. Confirm the restore action. You will see the message: User successfully restored;
  5. When you restore a deleted user, the Azure/Microsoft 365 group membership and the set of assigned AAD licenses are fully restored as well.
The previous article describes how to restore deleted objects in on-premises Active Directory.

Also, you can restore a user in AAD/Microsoft 365 using PowerShell. To do it, you must use the MSOnline and AzureAD Powershell modules or Microsoft Graph API.

You can display a list of all deleted users (with the full list of attributes) using this command:

Get-MsolUser -ReturnDeletedUsers | fl *

You can display specific user properties only (name, ID, user creation or deletion date):

Get-MsolUser -ReturnDeletedUsers | select DisplayName, ObjectId,SoftDeletionTimestamp, WhenCreated

Get-MsolUser -ReturnDeletedUsers - list deleted users with powershell

You can restore a user by their ObjectID:

Restore-AzureADMSDeletedDirectoryObject -Id 98813128-ffb1-4c55-b11f-6c58d7d66

Restore-AzureADMSDeletedDirectoryObject

You can also restore a user by a UPN using the Restore-MsolUser cmdlet:

Restore-MsolUser -UserPrincipalName "[email protected]"

  • In the previous command, you may use an optional parameter –AutoReconcileProxyConflicts, which allows you to assign a new proxy address to a user if the old one is busy
  • or you can set a new UPN immediately using the option -NewUserPrincipalName "[email protected]"

Restore-MsolUser - restore deleted Microsoft 365 users

To permanently delete a user from AAD, the following command is used:

Remove-MsolUser –userprincipalname [email protected] -RemoveFromRecycleBin

You can also use the Azure AD audit logs to search for user deletion events. For example, the following script will find a user deletion event (you will see who deleted a user and when), return a UPN and ObjectID of a deleted user:

Import-Module AzureADPreview -UseWindowsPowerShell

Use this command to load the module for the classic Windows PowerShell version into the PowerShell Core.

Get-AzureADAuditDirectoryLogs  -Filter "category eq 'UserManagement' and OperationType eq 'Delete'" |where-object TargetResources -like ("*AlexTest*")|select-object -ExpandProperty TargetResources

Get-AzureADAuditDirectoryLogs - find Azure AD user deletion event

You can restore a user by their object ID using the Restore-AzureADMSDeletedDirectoryObject cmdlet.

0 comment
0
Facebook Twitter Google + Pinterest
previous post
Fix: Remote Desktop Services Is Currently Busy
next post
Sending an E-mail to a Microsoft Teams Channel

Related Reading

How to Connect VPN Before Windows Logon

November 14, 2023

Removing Azure Arc Setup Feature on Windows Server...

November 9, 2023

Send Emails with Microsoft Graph API and PowerShell

November 6, 2023

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • How to Connect VPN Before Windows Logon

    November 14, 2023
  • Removing Azure Arc Setup Feature on Windows Server 2022

    November 9, 2023
  • Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

    November 7, 2023
  • Send Emails with Microsoft Graph API and PowerShell

    November 6, 2023
  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Checking User Sign-in Logs in Azure AD (Microsoft 365)
  • Configuring Azure AD Password Policy
  • How to Reset User Password in Azure Active Directory (Microsoft 365)
  • Enable or Disable MFA for Users in Azure/Microsoft 365
  • Removing Azure Arc Setup Feature on Windows Server 2022
  • Manage Groups in Azure AD and Microsoft 365 Using PowerShell
  • Disable Welcome Message for Microsoft 365 Groups
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top