Efficiently Restore Multiple Files on OneDrive with PowerShell

OneDrive is a powerful cloud storage platform that integrates seamlessly with Microsoft 365 applications.

While OneDrive offers automated backups and version control for files, situations may arise where you need to restore multiple files in bulk—such as after accidental deletions, overwrites etc.

We have encountered with one such situation and doing it from GUI would takes ages so we have written this small script that you can utilize:

Prerequisites for this Solution:

Download the script from Git or PowerShell gallery from below links:
Git:
https://github.com/VikasSukhija/Downloads

BulkRestoreOnedriveFiles.ps1

PowerShell Gallery:

https://www.powershellgallery.com/packages/BulkRestoreOnedriveFiles

Install-Script -Name BulkRestoreOnedriveFiles

After downloading the BulkRestoreOnedriveFiles.ps1 script, navigate to the directory where the script is located using PowerShell

cd c:\ BulkRestoreOnedriveFiles

To begin, execute the script with the appropriate parameters for the date range and OneDrive site URL. Here’s an example:

.\BulkRestoreOnedriveFiles.ps1 -startDate “2024-07-20” -endDate “2024-07-29” -onedrivesiteURL onedrivesiteurl

On the first run, it’s recommended to log what will be restored without actually restoring the files. You can achieve this by temporarily hashing out the actual restore command.

In the script, find the line that performs the restore action and comment it out:

#Restore-PnPRecycleBinItem -Identity $id -force

If you want to restore only certain file types, such as .csv files, you can further filter the items before running the restore process.

In the script, you can modify the $restorefiles variable as follows:

$restorefiles = $filteredItems # you can add filter here if you want | where{$_.Title -like “*.csv”}

By following these steps, you can safely test and execute bulk restore operations on OneDrive files with granular control over what gets restored.

 

 

Thanks for reading and downloading…

Tech Wizard

https://techwizard.cloud

PowerShell Fast Track

Leave a comment