Best Practice for restoring OneDrive for Deleted users


In the following examples we will give a brief about the retention policy scenarios for OneDrive For business.

2 methods

Compliance center search contents and SharePoint admin center

Difference From compliance center From SharePoint
retentionAfter and beforeAfter user deleted
configurationContent searchPowerShell
ResultsJust the contentsFull path and structure of data and folders
Difference Between retention from compliance center and from OneDrive admin center

In this scenario we will give a brief about the retention policy

The first method

 is using the security and compliance center to retain OneDrive Data, this method is used for retaining data for compliance reasons also the data will be retrieved using content search.

  • Comply proactively with industry regulations and internal policies 
  • Reduce your risk in the event of litigation or a security breach
  • Help your organization to share knowledge effectively
Creating retention policy

data will be retrieved using the search content in the compliance center.

The second Method which is recommended

The result shall look like that after finish go to the URL of the user.

A user’s OneDrive URL is based on their username. For example, https://domain-my.sharepoint.com/personal/user1_domain_com.

how the restored Data is displayed

Set the OneDrive retention for deleted users

Go to OneDrive admin portal

OneDrive for Business Admin Preview

Enter the number of days you want to keep the OneDrive files in the Days to retain files in OneDrive after a user account is marked for deletion.

The minimum value is 30 days and the maximum value is 3650 days (10 years).

This is the process of deletion

OneDrive retention and deletion – OneDrive | Microsoft Docs

When the account is deleted

The account deletion is synced to sharepoint and the OneDrive Cleanup job runs OneDrive Marked for deletion the user will appear in the deleted users for 30 days

Note

Retention policies always take precedence to the standard OneDrive deletion process, so content included in a policy could be deleted before 30 days or retained for longer than the OneDrive retention

Restore the Data

Let’s start with the restore process installing the sharepoint PowerShell

The following is all the commands needed

all PowerShell commands

#install sherepoint online Module

Install-Module -Name Microsoft.Online.SharePoint.PowerShell

# connect to your sharepoint tenant

Connect-SPOService -Url https://mydomain-admin.sharepoint.com

# get list of deleted users URL

Get-SPODeletedSite -IncludeOnlyPersonalSite | FT url

#restore the user

Restore-SPODeletedSite -Identity  https://yourdomain-my.sharepoint.com/deleteduser/deleteduser_yourdomain_com

# assign admin to open

Set-SPOUser -Site  https://yourdomain-my.sharepoint.com/deleteduser/deleteduser_yourdomain_com -LoginName admin@yourdomain.com -IsSiteCollectionAdmin $True

# When you permanently delete a OneDrive, you will not be able to restore it.

Remove-SPOSite -Identity  https://yourdomain-my.sharepoint.com/deleteduser/deleteduser_yourdomain_com

Remove-SPODeletedSite -Identity  https://yourdomain-my.sharepoint.com/deleteduser/deleteduser_yourdomain_com

The following is explanation of each command

Download SharePoint Online Management Shell from Official Microsoft Download Center

Connect-SPOService -Url Connect-SPOService -Url https://yourdomain-admin.sharepoint.com

Now connect to know if the user’s data is available or not

Get-SPODeletedSite -Identity <URL>

A user’s OneDrive URL is based on their username.

For example, https://yourdomain-my.sharepoint.com/personal/user1_contoso_com

Lets say you don’t know his URL then run the following command to get all deleted users

If his username appears then it can be restored

Get-SPODeletedSite -IncludeOnlyPersonalSite | FT url

Then restore onedrive to active state

Restore-SPODeletedSite -Identity <URL>

Assign administrator to view the data

Set-SPOUser -Site <URL> -LoginName <UPNofDesiredAdmin> -IsSiteCollectionAdmin $True

After you finish remove then delete

Remove-SPOSite -Identity <URL>

Remove-SPODeletedSite -Identity <URL>

Restore a deleted OneDrive – OneDrive | Microsoft Docs

Advertisement

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.