Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • 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 2012
    • 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)?

March 16, 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 alextestusr@woshub.com, for example, after you delete the user the object ID in AAD is added to the beginning: 98813128-ffb1-4c55-b11f-6c58d7dalextestusr@woshub.com
  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 "AlexTest@woshub.com"

  • 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 "AlexTest2@woshub.com"

Restore-MsolUser - restore deleted Microsoft 365 users

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

Remove-MsolUser –userprincipalname name@woshub.com -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

Configure Network Settings on Windows with PowerShell: IP...

March 24, 2023

Exchange Offline Address Book Not Updating in Outlook

March 21, 2023

Sending an E-mail to a Microsoft Teams Channel

March 17, 2023

Send-MailMessage: Sending E-mails with PowerShell

March 14, 2023

Clear Cache and Temp Files in User Profiles...

March 13, 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 Run Program without Admin Privileges and Bypass UAC Prompt?

    March 24, 2023
  • Configure Network Settings on Windows with PowerShell: IP Address, DNS, Default Gateway, Static Routes

    March 24, 2023
  • Exchange Offline Address Book Not Updating in Outlook

    March 21, 2023
  • Attaching Host USB Devices to WSL or Hyper-V VM

    March 20, 2023
  • Sending an E-mail to a Microsoft Teams Channel

    March 17, 2023
  • How to Restore Deleted Users in Azure AD (Microsoft 365)?

    March 16, 2023
  • Fix: Remote Desktop Services Is Currently Busy

    March 15, 2023
  • Send-MailMessage: Sending E-mails with PowerShell

    March 14, 2023
  • Clear Cache and Temp Files in User Profiles on Windows (RDS) with PowerShell and GPO

    March 13, 2023
  • Prevent Users from Creating New Groups in Microsoft 365 (Teams/Outlook)

    March 6, 2023

Follow us

woshub.com
  • Facebook
  • Twitter
  • RSS
Popular Posts
  • Checking User Sign-in Logs in Azure AD (Microsoft 365)
  • How to Reset User Password in Azure Active Directory (Microsoft 365)?
  • Enable or Disable MFA for Users in Azure/Microsoft 365
  • Manage Groups in Azure AD and Microsoft 365 Using PowerShell
Footer Logo

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


Back To Top