When a user is deleted and then re-created with the same username in Microsoft 365, OneDrive may still reference the old account. This occurs because the new account, despite having the same User Principal Name (UPN), possesses a different unique ID. Consequently, SharePoint and OneDrive might retain references to the outdated ID, leading to access issues.
This guide outlines the steps to remove the old user account remnants using Microsoft Graph PowerShell and SharePoint Online Management Shell, ensuring that OneDrive correctly associates with the new user account.
Step 1: Install Microsoft Graph PowerShell Module
First, install the Microsoft Graph PowerShell module to interact with Microsoft 365 services.
Open PowerShell with administrative privileges.
Run the following command:
Install-Module -Name Microsoft.Graph
If prompted to install the NuGet provider, type Y and press Enter.
Step 2: Connect to Microsoft Graph
Establish a connection to Microsoft Graph with the necessary scopes.
Connect-MgGraph -Scopes "User.ReadWrite.All", "Group.ReadWrite.All"
Enter your administrator credentials when prompted.
Step 3: Identify the Old User Account
Retrieve a list of all user accounts to identify the old user account that needs to be removed.
Get-MgUser -All | Format-List ID, DisplayName, Mail, UserPrincipalName
Note down the UserPrincipalName or ID of the old user account.
Step 4: Remove the Old User Account
Use the Remove-MgUser cmdlet to delete the old user account from Azure Active Directory.
Remove-MgUser -UserId "OldUser@contoso.com#EXT#@contoso.onmicrosoft.com"
Replace "OldUser@contoso.com#EXT#@contoso.onmicrosoft.com" with the actual UserPrincipalName or ID of the old user account.
Step 5: Remove the User from SharePoint’s UserInfo List
Even after deleting the user from Azure AD, remnants may persist in SharePoint’s UserInfo list. Removing these ensures complete dissociation.
Option 1: Manual Removal via SharePoint Site
Navigate to the SharePoint site that the user had access to. This may be any user’s SharePoint Site or OneDrive where access has been provided to the old user account.
Append the following to the site’s URL: /_layouts/15/people.aspx?MembershipGroupId=0
For example: https://contoso.sharepoint.com/_layouts/15/people.aspx?MembershipGroupId=0
Locate and select the old user account.
From the Actions menu, choose “Delete Users from Site Collection.
Option 2: Using SharePoint Online Management Shell
Install and open the SharePoint Online Management Shell.
Connect to your SharePoint admin centre:
Connect-SPOService -Url https://contoso-admin.sharepoint.com
Remove the user from each site collection they had access to:
Remove-SPOUser -Site https://contoso.sharepoint.com/sites/SiteName -LoginName "OldUser@contoso.com"
Replace https://contoso.sharepoint.com/sites/SiteName with the actual site URL and "OldUser@contoso.com" with the user’s login name.
Step 6: Clear Browser Cache
SharePoint may cache user information in the browser. Clearing the browser cache ensures that outdated data doesn’t persist.
- Open your browser settings.
- Navigate to the privacy or history section.
- Clear browsing data, ensuring that cookies and cached images/files are selected.
Conclusion
By following these steps, you can effectively remove all traces of the old user account, ensuring that OneDrive and SharePoint correctly associate with the new user account. This process helps prevent access issues and ensures a smooth user experience.
For more detailed information, refer to Microsoft’s official documentation: Remove users from SharePoint.