I recently deleted a user from Azure Active Directory and am looking to undo this action using Azure CLI. Before reaching out here, I tried looking up documentation and relevant commands but haven't found a clear solution yet.
To list the deleted users, make use of below command:
az rest --method GET --url "https://graph.microsoft.com/v1.0/directory/deletedItems/microsoft.graph.user"
Note that: Deleted users will be available up to 30 days to restore. After 30 days the user will be permanently deleted and you will not be able to restore.
To restore the user from Azure CLI, make use of below command:
az rest --method POST --url "https://graph.microsoft.com/v1.0/directory/deletedItems/ObjectID/restore"
The user is restored successfully:
Otherwise, you can also make use of Azure PowerShell:
To list the deleted users, make use of below commands
Connect-MSOLService
Get-MsolUser -ReturnDeletedUsers
Restore-MsolUser -UserPrincipalName <string> -AutoReconcileProxyConflicts -NewUserPrincipalName <string>