Recover large amount of files from Recycle Bin in OneDrive

2

I have an account for OneDrive for Business through my university email. Slightly more than one month ago I deleted some files by mistake, and of course, I just noticed it.

I now found all the files in the OneDrive's Recycle Bin in the website, the problem is that they are 6000+ single files and I'd need all of them. If I try to select them all (struggling) it gives a timeout error.

So I'm forced to manually restore them by groups of 35-40 files at a time. I made a quick computation and it will take me more than 5 hours in this way.

Does it exist a faster and more automatic solution to the problem?

ale93p

Posted 2018-10-16T14:45:51.107

Reputation: 21

Recycle Bin within OneDrive or Recycle Bin within Windows. Edit your question to clarify where these deleted files are located. – Ramhound – 2018-10-16T15:14:22.633

"more than 5 hours" is ok.. Incomplete restoration is not. Keep it up, you are on the right track there... ( : – p._phidot_ – 2018-10-16T18:37:56.190

@Ramhound edited – ale93p – 2018-10-17T07:12:01.750

@p.phidot I don't think it's the right track for Computer Science in 2018 – ale93p – 2018-10-17T07:12:06.170

agreed.. IMHO when I stump at things like these.. I can choose whether to wait.. or use HDD restoration tools straight away.. || or I can just agree to disagree. || Sorry I didn't answer your question. just my 2 cent. ( : – p._phidot_ – 2018-10-17T11:11:11.880

@p.phidot if would be a matter of waiting 5 hours there would be no problem for me, I'm ok with passive waiting. The problem is that I need to manually select 40 files, press restore, wait to finish, select 40 files, press restore, and so on. – ale93p – 2018-10-17T12:09:10.540

agreed... /(^_^) – p._phidot_ – 2018-10-18T06:47:00.073

Answers

0

You can automate the restoration of files deleted that are in the OneDrive Recyble Bin with Poweshell.

The code algorithm would more or less:

foreach ($fileitem in $FilteredRecycleBinArray) 
    { 
    $filename = $fileItem.Title 
    $fileitem.Restore() 
    try { 
        $ctx.ExecuteQuery() 
        logwrite -Logstring "Item $filename restored successfully" -type info 
        } 
    catch  
        { 
        logwrite -Logstring "Item $filename failed to restore with error: '$_.Exception.Message'" -type error 
        } 
    }

Relevant related code:

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($OnedriveUrl)

And:

$Recyclebinarray=$ctx.Site.RecycleBin
$ctx.Load($Recyclebinarray)
try     {$ctx.ExecuteQuery()}
catch   {logwrite -Logstring "Failed Collecting all deleted Items from $OnedriveURL with error: '$_.Exception.Message'" -type error
        break}

Here you have a full example:

https://gallery.technet.microsoft.com/office/Restore-deleted-files-in-a268fdcd

Eloy Roldán Paredes

Posted 2018-10-16T14:45:51.107

Reputation: 101

@eloy I suppose this is the right way, the only problem is that the script requires the credential of the 365 admin and I'm just a user, through the account of my university, so unfortunately I cannot use this solution. – ale93p – 2018-10-17T12:06:29.133

@ale93p If you have access to the O365 recyble bin with your credentials I suppose there should be a method (this or other similar) that enables you to automate the restoration. – Eloy Roldán Paredes – 2018-10-17T16:52:48.983

I acces through the university email, which should normaly require an external authetication. So, or I should use something else as username, or it gives me:

Checking if alessio.pagliari@unice.fr as site admin for https://unice-my.sharepoint.com/personal/alessio_pagliari_unice_fr 18-10-2018 09:12:06 - Failed to check if alessio.pagliari@unice.fr as site admin for https://unice-my.sharepoint.com/personal/alessio_pagliari_unice_fr with error: 'Exception calling "ExecuteQuery" with "0" argument(s): "The type initializer for 'Microsoft.Win32.Registry' threw an exception.".Exception.Message' – ale93p – 2018-10-18T07:14:44.743