Manage Deleted SharePoint Sites (Includes OneDrive)
Prerequisites
- You must be a Global Admin or SharePoint Admin
- Use Windows PowerShell 5.1 or later
- Ensure the SharePoint Online Management Shell module is installed
You can install it using:Install-Module -Name Microsoft.Online.SharePoint.PowerShell
Restore a User’s OneDrive
This guide explains how to restore a deleted OneDrive for a former or current user in Microsoft 365 using PowerShell. It also includes how to assign another user as the site collection admin for data access.
Steps
1. Import the SharePoint Online PowerShell Module
Import-Module Microsoft.Online.SharePoint.PowerShell -UseWindowsPowerShell
If you are using PowerShell 7+, you must include the
-UseWindowsPowerShellswitch when importing the module.
2. Connect to SharePoint Online Admin Center
Connect-SPOService -Url https://jranck-admin.sharepoint.com
3. List Deleted OneDrive Sites
Get-SPODeletedSite -IncludeOnlyPersonalSite
4. Search for a Specific Deleted User
Get-SPODeletedSite -IncludeOnlyPersonalSite | Where-Object {$_.Url -like '*<username>*'}
5. Restore the Deleted OneDrive
Restore-SPODeletedSite -Identity https://jranck-my.sharepoint.com/personal/<username>_jranck_com
6. Assign a Site Collection Admin
Set-SPOUser -Site https://jranck-my.sharepoint.com/personal/<user>_jranck_com -LoginName <admin_upn> -IsSiteCollectionAdmin $True
7. Remove the Site After Recovery
After accessing and backing up the data, you can remove the OneDrive:
Remove-SPOSite -Identity https://jranck-my.sharepoint.com/personal/<username>_jranck_com