Category Archives: OneDrive

Restore Items from OneDrive Recycle Bin using Powershell

There are situation when you need to restore large amount of data form OneDrive Recycle bin using PowerShell.

We can using SharePoint PnP PowerShell module for this.

Import the module

Install-Module -Name "PnP.PowerShell" -Force

Now for example you want to Restore OneDrive Recycle Bin of

Connect user’s OneDrive using below command, you need to provide end users credentials when requested.

Connect-PnPOnline  -Url -Interactive

Now you can get recycle bin items of the user, if there are so many items, you can specify the limit

Get-PnPRecycleBinItem -FirstStage
Get-PnPRecycleBinItem -SecondStage

If you want to restore just one item, you can specify ID of that Item.

You can also restore all Items in one go.

Get-PnPRecycleBinItem | Restore-PnPRecycleBinItem -Force

We can use filter also, use below command to restore items deleted in last 5 days, where item name contains “Project Related”

$restoreDate = (Get-Date).AddDays(-5)
Get-PnPRecycleBinItem -Firststage | where {($_.DeletedDate -gt $restoreDate) -and ($_.Title  -Like ‘*ProjectRelated*’)} | Restore-PnpRecycleBinItem -Force

How to Copy Other User’s OneDrive Data to your OneDrive

There are situations when we need to copy one user’s OneDrive data to another user’s OneDrive. For example a user leaving company and his manager wants all the project related files from his OneDrive. By default when we remove user’s license OneDrive data is preserved for 30 days which can be increased. If we want to preserve files longer than this, we can either enable retention hold on OneDrive or copy data to another user’s OneDrive.

We can follow below process to Copy OneDrive data.

  • Grant permissions on user’s OneDrive to his manager How to grant permissions ?
  • Generate OneDrive link and provide the link to user
    • Login Microsoft Admin portal
    • Select the user for which you want to save the data
    • Go to OneDrive Tab and click on “Create link to access file”
  • Now user’s manager can copy the data
    • Copy the link and provide to end user to access files of the user leaving
    • Open the link on user’s manager computer and select the folders you want to copy to his OneDrive
  • Click on “Copy To” and the Manager will option to copy to his OneDrive.
  • Select “Your OneDrive”. You will have option to Copy to existing folders or you can create a new folder also.
  • Depending on the size of data, you will start seeing files and folders in your OneDrive.

How to grant a user permission to access another user’s oneDrive

When an employee leaves your organization, the management wants to access their data to review it and give it a new employee or want to backup the data.

Once you remove the license and delete the user, you will have 30 days by default (can be increased from OneDrive admin center) to access user’s OneDrive data, after 30 days the data will be deleted.

We can allows other users to access OneDrive data using below methods.

Option 1 – Using user’s OneDrive link from M365 Admin center

In the admin center, go to the Users > Active users page.
Select a user.
In the right pane, select OneDrive. Under Get access to files, select Create link to files.

Click on this link and you will get redirected to the user’s OneDrive in your browser window.

Replace OneDrive with mngsiteadmin, so the link will become line below.

Add the new user in the permissions list and click Ok. don’t remove any permissions from here.

The new user will have permissions to the OneDrive

Option 2 – Using SharePoint Admin Center.

  • Login SharePoint Admin Center
  • On the left hand pane open the “more features”
  • Under User Profiles, select Open.
  • Under People, select Manage User Profiles.
  • Enter the user’s name and click Find.
  • Right-click on the user’s name and select Manage Site Collection Owners.
  • Add a secondary admin in the “Site Collection Administrators” and Click OK