Delete all the guest users from m365 tenant
✅ Prerequisites
Install the module (if not installed)
Install-Module Microsoft.Graph -Scope CurrentUser✅ Step 1: Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.ReadWrite.All"✅ Step 2 (Optional but Recommended): Export Guest Users to CSV
Get-MgUser -Filter "userType eq 'Guest'" -All |
Select DisplayName, UserPrincipalName, Id |
Export-Csv "GuestUsers_Backup.csv" -NoTypeInformation✅ Step 3: Delete All Guest Users
🔹 Dry Run (Recommended first)
🔹 Actual Deletion
✅ Step 4: Verify
🔒 Safety Enhancements (Optional)
Exclude specific domains
Exclude specific users
📝 Notes
Last updated