Remove-MgUser?

What is Remove-MgUser?

The Remove-MgUser cmdlet in Microsoft Graph PowerShell is used to delete a user account from Microsoft 365. It can target accounts using either the user’s unique ID (GUID) or their User Principal Name (UPN).

Why Use Remove-MgUser?

Automating user removal with Remove-MgUser allows administrators to quickly deprovision accounts in bulk, ensuring faster offboarding, maintaining security, and preventing unauthorized access without manually navigating the Microsoft 365 admin center.


Prerequisites

Before using Remove-MgGroup, ensure you have the Microsoft Graph PowerShell module installed and the necessary permissions granted.

Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "Group.ReadWrite.All"

How to Use Remove-MgUser?

Syntax:

Remove-MgUser -UserId <userid>

The cmdlet can be used with a UPN or the unique user ID. It supports preview mode with -WhatIf and confirmation prompts with -Confirm for safer execution.


Remove-MgUser Examples

  • Remove a User by UPN
  • Remove-MgUser -UserId "john.doe@contoso.com"
  • Remove a User by User ID
  • Remove-MgUser -UserId "12345abc-6789-def0-1234-56789abcdef0"
  • Remove a User with Confirmation
  • Remove-MgUser -UserId "jane.doe@contoso.com" -Confirm
  • Preview User Removal
  • Remove-MgUser -UserId "jane.doe@contoso.com" -WhatIf
  • Bulk Remove Users from a CSV File
  • $users = Import-Csv "C:\Path\To\Users.csv"
    foreach ($user in $users) {
        Remove-MgUser -UserId $user.UserPrincipalName 
    }
                                                

Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.

Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.

© Your Site Name. All Rights Reserved. Design by HTML Codex