questionDelete all the guest users from m365 tenant

Below is a safe and commonly used PowerShell script to delete all Guest users from a Microsoft 365 (Entra ID / Azure AD) tenant.

⚠️ Important warning This action is irreversible. All Guest users (UserType = Guest) will be permanently deleted. It’s strongly recommended to export the list first or run in WhatIf mode.


✅ Prerequisites

  • Role: Global Administrator or User Administrator

  • PowerShell 7+ recommended

  • Module: Microsoft Graph PowerShell

Install the module (if not installed)

Install-Module Microsoft.Graph -Scope CurrentUser

✅ Step 1: Connect to Microsoft Graph

Connect-MgGraph -Scopes "User.ReadWrite.All"

Get-MgUser -Filter "userType eq 'Guest'" -All |
Select DisplayName, UserPrincipalName, Id |
Export-Csv "GuestUsers_Backup.csv" -NoTypeInformation

✅ Step 3: Delete All Guest Users

🔹 Actual Deletion


✅ Step 4: Verify

If nothing returns, all Guest users are deleted.


🔒 Safety Enhancements (Optional)

Exclude specific domains

Exclude specific users


📝 Notes

  • Deleted users can be restored within 30 days from Deleted Users in Entra ID

  • This does not delete external users from their home tenants

  • Best practice: Run during a maintenance window

Last updated

Was this helpful?