3

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
  • 131

1 Answers1

1

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