Monthly Archives: May 2021

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