How to delete Microsoft Entra ID users using Remove-MgUser

Deleting Microsoft Entra ID users

Deleting Microsoft Entra ID users is a critical administrative task driven by various needs, including revoking access for ex-employees, cleaning up inactive users, security, and compliance. While Graph PowerShell's Remove-MgUser command, an alternative to the New-AzureADUser command, can be used to delete Microsoft Entra ID users, its complexity and non-intuitive interface make it a challenging option. On the other hand, ADManager Plus, a Microsoft 365 management and reporting tool, simplifies this process, allowing administrators to quickly delete users in just a few clicks.

  • ADManager Plus
  • PowerShell
 

Steps to delete Microsoft Entra ID users using ADManager Plus

  1. Log in to ADManager Plus.
  2. Navigate to Microsoft 365 > Management > Delete Users. If you want to delete users from the recycle bin, click the Hard Delete Users option below Delete Users.
  3. From the Microsoft 365 Tenant drop-down list, select the tenant in which the users you wish to delete are present.
  4. Select the users or upload a CSV file to delete users in bulk.
  5. Click OK.
Delete Microsoft Entra ID users using ADManager Plus

Delete Microsoft Entra ID users using Microsoft Graph PowerShell

Prerequisites

Before using the Remove-MgUser cmdlet, ensure the following:

  • The Microsoft Graph PowerShell module is installed. If not, install it using this script:
    Install-Module Microsoft.Graph -Scope CurrentUser
  • Connect to Microsoft Graph PowerShell with the following permissions (from least to most privileged) to delete Microsoft Entra ID users.
    User.DeleteRestore.All,
    User.ReadWrite.All,
    DeviceManagementServiceConfig.ReadWrite.All,
    DeviceManagementManagedDevices.ReadWrite.All,
    DeviceManagementConfiguration.ReadWrite.All,
    DeviceManagementApps.ReadWrite.All,

Using the Remove-MgUser command to delete Microsoft Entra ID users

The Remove-MgUser cmdlet can be used in Microsoft Graph PowerShell to delete Microsoft Entra ID users. Here's the syntax:

Remove-MgUser
-UserId <String>
[-IfMatch <String>]
[-ResponseHeadersVariable <String>]
[-Headers <IDictionary>]
[-PassThru]
[-ProgressAction <ActionPreference>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]

Example use cases and scripts using the Remove-MgUser cmdlet

Example 1: Remove a user

This script removes a user.

Remove-MgUser -UserId '5c442efb-5e66-484a-936a-91b6810bed14'

Example 2: Remove a user with a confirmation

This script removes a user after the user is prompted for a confirmation.

Remove-MgUser -UserId '3f80a75e-750b-49aa-a6b0-d9bf6df7b4c6' -Confirm

Supported parameters

The following table contains some parameters that can be used along with the Remove-MgUser command to efficiently delete Microsoft Entra ID users.

Parameters Description
-Headers This parameter allows you to add optional headers to the request.
-PassThru This parameter returns true when the command succeeds.
-ResponseHeadersVariable This parameter allows you to add option response header variables.
-UserId This parameter displays the unique identifier of the user.
-WhatIf This parameter displays the outcome if the cmdlet is executed.

Limitations of using Graph PowerShell scripts to delete Microsoft Entra ID users

  • Graph PowerShell requires IT admins to upgrade from Azure AD PowerShell and have familiarity with PowerShell scripting.
  • The Microsoft Graph API imposes throttling limits, which may affect performance when deleting users in bulk.
  • Manual script execution is time-consuming and increases administrative effort. The complexity of bulk deletion scripts poses a significant risk of accidental user deletion.
  • Identifying and troubleshooting errors can be time-consuming and requires technical expertise.
  • The lack of an intuitive interface makes the overall experience less user-friendly, particularly for those new to scripting.

Highlights of using ADManager Plus to delete Microsoft Entra ID users

  • Manage and report on users from an easy-to-use interface, eliminating the need for complex PowerShell scripting or Graph API knowledge.
  • Simplify bulk operations through automation capabilities, optimizing for large-scale environments, and eliminating the need for complex scripts.
  • Use pre-built or custom templates to standardize management and reporting tasks.
  • Generate customizable reports to gain detailed insights on deleted objects and export them in various formats, like CSV or HTML.
  • Delegate specific management and reporting tasks to technicians without granting them excessive permissions.

Automate Microsoft Entra ID user deletion with ADManager Plus

 
  • Deleting Microsoft Entra ID users
  • Deleting Microsoft Entra ID users using ADManager Plus
  • Deleting Microsoft Entra ID users using Microsoft Graph PowerShell
  • Limitations of using Graph PowerShell scripts to delete Microsoft Entra ID users
  • Highlights of using ADManager Plus to delete Microsoft Entra ID users
The one-stop solution to Active Directory Management and Reporting
Email Download Link