How to delete users from O365.

This article will explain how to delete users from O365 which will help you to manage the users in O365 admin center

Please follow below steps to delete users from O365

Login to O365 admin center by browsing : https://admin.microsoft.com/

Navigate to Users–> Active users

select users which you want to get rid of and hit delete users ( please check this article in which we have added users https://microbrother.com/how-to-create-bulk-users-in-o365-admin-center/)

You can restore deleted users and their data, except for calendar items and aliases, for up to 30 days after you delete them.

Licenses will be available to assign to other users immediately. After 30 days, data will be permanently deleted.

We are done here.

Deleted users can be seen in Teams admin center

PowerShell script for above manual task

# for single user
# Install Microsoft Graph module if not already installed
Install-Module Microsoft.Graph -Force -AllowClobber

# Connect to Microsoft Graph with necessary permissions
Connect-MgGraph -Scopes "User.ReadWrite.All"

# Variables for the user to delete
$UserPrincipalName = "user1@yourdomain.com"

# Delete the user
Remove-MgUser -UserId $UserPrincipalName -Confirm:$true

Write-Host "User $UserPrincipalName has been deleted."

# for multiple users
UserPrincipalName
user1@yourdomain.com
user2@yourdomain.com
user3@yourdomain.com

# Install Microsoft Graph module if not installed
Install-Module Microsoft.Graph -Force -AllowClobber

# Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.ReadWrite.All"

# Path to CSV
$CSVPath = "C:\Scripts\users.csv"

# Import CSV and delete each user
$Users = Import-Csv -Path $CSVPath

foreach ($User in $Users) {
    try {
        Remove-MgUser -UserId $User.UserPrincipalName -Confirm:$false
        Write-Host "Deleted user: $($User.UserPrincipalName)"
    }
    catch {
        Write-Host "Failed to delete user $($User.UserPrincipalName): $_"
    }
}

Write-Host "All users in CSV processed."

Conclusion:

Post following this blog reader will be able to delete users from O365

You can also read this article https://microbrother.com/how-to-add-guest-users-in-o365/ to add guest users in O365

Also Read  How to create an user in Office 365

Thank you ☺️

Leave a Comment