Requirement: Delete User Profile in SharePoint Online using PowerShell
How to delete a User Profile in SharePoint Online?
If you are a SharePoint Online administrator and need to delete a user profile, this guide will show you how! Perhaps the user is no longer with your company, and you want to remove the orphaned profile from SharePoint Online. Regardless of the reason, Deleting user profiles is a straightforward process, and this article will walk through the steps necessary to delete a user profile in SharePoint Online. We will also show you how to use PowerShell to delete a user profile in SharePoint Online.
SharePoint Online user profiles get deleted by the UPA sync job (which we can’t control in SharePoint Online, BTW!) when a User account is deleted or disabled in Azure Active Directory or from Microsoft Admin Center. To delete a user profile in SharePoint Online manually, do the following:
- Sign in to https://admin.microsoft.com as a Global Admin or SharePoint Online Admin.
- In the left pane, under Admin centers, select SharePoint.
- In the left pane of the classic SharePoint admin center, select user profiles.
- Go to User profiles > Manage User Profiles > Search for your user
- Select the user and click on the “Delete” link to delete the user profile in SharePoint Online.
Deleting a user profile in CSOM is not implemented so far, as per https://docs.microsoft.com/en-us/sharepoint/dev/general-development/work-with-user-profiles-in-sharepoint
SharePoint Online: Delete User Profile using PowerShell
Open SharePoint Online Management Shell and run the below script to delete a user profile from SharePoint Online.
#Connect to SharePoint Online Connect-SPOService -Url https://thecrescenttech-admin.sharepoint.com #Remove User Profile Remove-SPOUserProfile -LoginName [email protected]
This PowerShell deletes the user profile in SharePoint Online. Make sure the user account is already deleted in the Azure Active Directory before removing the user profile. Otherwise, the profile may get created in the following user profile sync job! If you want to exclude some users from the User profile import (E.g., Service Accounts), set the filter in AD Connect from On-Premises Active directory!
Please note, this doesn’t delete the user entirely from SharePoint Online! Places like user information lists and metadata fields such as “Created By” and “Modified By” may refer to the deleted user profile. So, if you want to remove a user from SharePoint Online altogether, use: How to Delete a User from SharePoint Online Site using PowerShell?