Restore items

Brass Contributor

On September 23rd (3 days ago) a user deleted a large number of files from SharePoint online.

Files are still in 1st Recycle Bin.

My question is:

What would be the most simple command to restore those files?

 

I'm little confused because I'm not sure from which side to "attack" the issue.

 

Kind regards,

Dino

3 Replies

@DiVojich 

You can use Pnp cmdlet to restore the file with filters of the deleted user name and date filter.  Please refer the below script.

Get-PnPRecycleBinItem -firststage | Where-object {($_.DeletedDate -gt $Deletedate) -and ($_.DeletedByEmail -eq 'test@domain.com')} | Restore-PnpRecycleBinItem -Force

1)Run windows Power shell as administrator

2)Install this module
Install-Module SharePointPnPPowerShellOnline

3)Connecting to a specific site with the help of its URL
Note :- dont use '<>' braces any where

Connect-PnPOnline -Url <site URL>

Enter Global admin credentials when it gives you a prompt.

4)to check connection run below command it will show the list of deleted items of the this particular site

Get-PnPRecycleBinItem

5) Defining date variables
$today = (Get-Date)
$date1 = $today.date.addDays(-3)
$date2 = $today.date.addDays(0)

6)Run this command to restore the files as the date variable values like above -3 and 0 , so that the restored files are backed to these many days only and not includes all the files deleted by hte user over all

Get-PnPRecycleBinItem | ? {($_.DeletedDate -gt $date2 -and $_.DeletedDate -lt $date1) -and ($_.DeletedByEmail -eq 'xyz@domain.com' )} | Restore-PnPRecycleBinItem -Force


In emergency cases If you wish to restore all the files and folders deleted by a specific user from the specific site
Please repeate the obove steps 1-4 and then give the command in the below 5th step

5) Get-PnPRecycleBinItem -FirstStage | ? DeletedByEmail -eq 'xyz@domain.com' | Restore-PnpRecycleBinItem -Force

Wait for few minutes because we are restoring files in bulk
Note :- However there is a limitation to this script that it could retrieve only a fixed number of data files
for example what i observed is about 12000 files .
Scenario:- If you already restored the file among these 12000 files it will throw error so better don't try to do manually any attempt to restore before running this command .
Scenario 2:- After receiving this error If you try to rename the already restored empty folder you will receive a all the contents of the folder in the renamed folder and a seperately named with the original of the folder.
Example:- 1)folder A1 is deleted it is in the recylebin
2) you go to recycle bin and restore it from the bin
3) the folder will be restored to the originally location without any file in it
4) now if you try to restore using the folder again using this script
5)it wont restore and will give the error
6) If you try to rename existing A1 folder to B1
7) Then if you re enforce the script it will restore an empty folder A1 seperately
8) and the files under the folders will be restored to the location B1
9) the reason being, at the hardware level in the data center the actual location is now B1
10) so if you don't wanna rename every already restored folder please do not restore any file
before running script and it would behave normally
This is a very unusual behaviour caused by the team work of users and IT