Restore-OneDrive (the PowerShell way)

Recently I moved from OneDrive to OneDrive for Business (which is not automated task by the way…) and was hoping to have more control over my data and also email because I also migrated from Gmail to Exchange Online (that works great by the way).

I was not thinking about all the lab I’ve done in the tenant, so one day I got an email alert saying that multiple files where deleted from my OneDrive. Looked at the Recycle Bin in OneDrive and yes, there was plenty of deleted files… After some research I found the root cause, Retention Policy. Don’t mess with Retention Policies… 😉

To restore OneDrive, file by file you can select multiple files and then hit the Restore button in the OneDrive portal. But for 30.000 files? No… big no. At maximum I could restore about 700-1000 files at a time through the browser. And sometimes I had to wait to be able to restore more files. I need PowerShell!

OneDrive/SharePoint official Microsoft PowerShell module isn’t good for restore of OneDrive. But! The community had written the SharePointPnPPowerShellOnline module! (Install-Module SharePointPnPPowerShellOnline). Read more about the PnP PowerShell here: https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets?view=sharepoint-ps

So I started to write a PowerShell function to be able to restore all my files in the recycle bin. And here it is!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: