Delete an account

You can delete an existing from the directory. You must have at least the User Administrator role assignment to delete non-admin users in your organization. Those with the Privileged Authentication Administrator role can delete any users including other administrators.

Browse to Identity > Users > All user. Search for and select the user you want to delete, then select Delete user.

At this time the user is deleted and no longer appears on the All users page. The user can be seen on the Deleted users page for the next 30 days and can be restored during that time. To restore or remove a recently deleted user, from the menu select Deleted users. Review the list of users that are available to restore. Select the user, and choose Delete permanently or Restore user.

1. Find a user

You delete a user by its ID or by a user principal name. If you have this information, skip to the next step. There are severl options to find a user. The following example shows how to get a user account using a sign-in name.

GET https://graph.microsoft.com/v1.0/users?$select=displayName,id&$filter=identities/any(c:c/issuerAssignedId eq '{sign-in-name}' and c/issuer eq '{your-tenant-name}')
Connect-MgGraph -Scopes "User.ReadWrite.All"
Get-MgBetaUser -Property "displayName,id" -Filter "identities/any(c:c/issuerAssignedId eq '{sign-in-name}' and c/issuer eq '{your-tenant-name}')"


GET https://graph.microsoft.com/v1.0/users?$select=displayName,id&$filter=identities/any(c:c/issuerAssignedId eq 'someone@contosodemo.com' and c/issuer eq 'woodgrove.onmicrosoft.com')
Connect-MgGraph -Scopes "User.ReadWrite.All"
Get-MgBetaUser -Property "displayName,id" -Filter "identities/any(c:c/issuerAssignedId eq 'someone@contosodemo.com' and c/issuer eq 'woodgrove.onmicrosoft.com')"
 

1.1 Get the user ID

From the response, copy the id. For example,

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(displayName,id)",
    "value": [
        {
            "displayName": "Nicholas",
            "id": "11111111-0000-0000-0000-000000000000"
        }
    ]
}

DisplayName Id
Nicholas 11111111-0000-0000-0000-000000000000

2. Delete a user

You delete a user by its ID or by a user principal name. In the following request, replace the {user-id} with the user ID.

DELETE https://graph.microsoft.com/v1.0/users/{user-id}
Remove-MgBetaUser -UserId {user-id}


DELETE https://graph.microsoft.com/v1.0/users/11111111-0000-0000-0000-000000000000
Remove-MgBetaUser -UserId 11111111-0000-0000-0000-000000000000

3. Restore deleted user

You restore a recently deleted user by its ID. In the following request, replace the {user-id} with the user ID.

POST https://graph.microsoft.com/v1.0/directory/deletedItems/{user-id}/restore
Restore-MgDirectoryDeletedItem -DirectoryObjectId {user-id}


POST https://graph.microsoft.com/v1.0/directory/deletedItems/11111111-0000-0000-0000-000000000000/restore
Restore-MgDirectoryDeletedItem -DirectoryObjectId 11111111-0000-0000-0000-000000000000

4. Permanently delete

You permanently deletea recently deleted user by its ID. In the following request, replace the {user-id} with the user ID. Note, to run the comman, you must have the User Administrator role.

DELETE https://graph.microsoft.com/v1.0/directory/deletedItems/{user-id}
Remove-MgDirectoryDeletedItem -DirectoryObjectId {user-id}


DELETE https://graph.microsoft.com/v1.0/directory/deletedItems/11111111-0000-0000-0000-000000000000
Remove-MgDirectoryDeletedItem -DirectoryObjectId 11111111-0000-0000-0000-000000000000
Loading...