Today, one of my supervisors asked me if I could recover the data from a former employee's OneDrive (whose account has been deleted).
So I got right down to work and started researching on that topic.
The result is this script:
# Requirements: # - Azure Powershell Module # Connect with Sharepoint and change <organisation> to a working value $UserCredential = Get-Credential Connect-SPOService -Url https://<organisation>-admin.sharepoint.com -Credential $UserCredential # Capture and Select a deleted OneDrive URL $url = (Get-SPODeletedSite -IncludeOnlyPersonalSite | Out-GridView -PassThru).URL # Restore One Drive Restore-SPODeletedSite -Identity $url # Transfer rights to the person that should gain access using the persons <upn> Set-SPOUser -Site $url -LoginName <upn> -IsSiteCollectionAdmin $True # Open the recovered OneDrive web page with the standard browser Start-Process $url
Additional helpful information:
- the default retention period for a deleted OneDrive is 30 days but you can extend this by using this cmdlet
SetSPOTenant -OrphanedPersonalSitesRetentionPeriod <int32>