Requirement: Delete User Profile in SharePoint Online using PowerShell
How to delete a User Profile in SharePoint Online?
SharePoint Online user profiles get deleted when a User account is deleted or disabled in Active Directory. To delete a user profile in SharePoint Online, 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 user profile in SharePoint Online. Make sure the user account is already deleted in Azure Active Directory, prior to remove the user profile. Otherwise, Profile may get created in the next user profile import job! If you want to exclude some users from User profile import (E.g. Service Accounts), set the filter in AD Connect from On-Premises Active directory!