While technology is great and can do wonderful things, it is only as competent as the person who is using the computer. Humans are not infallible and can make errors. Often times, they are stupid and unintentional.
We recently needed to restore files that were mistakenly deleted by a user. This is not a major issue. However, the recycle bin in question contained over 4 000 items. As we are well aware, trying to find something in the recycle bin can be tedious, especially when you have lots of items. To top it off, there are currently no search functions available for recycle bins.
Running the script.
We needed to view the items and write a script to do so. Below is the script which is to be run from the SharePoint Online Management Shell. The PnP module must also be installed as per the first line in the script.
Some prerequisites are required:
• Once downloaded, run it as Administrator.
• Install the PnP Module by using the script
Install-Module SharePointPnPPowerShellOnline in the SharePoint Online Management Shell;
• Enter in your Site URL using
$SiteURL = "https://sitename.sharepoint.com/"
• Hit Enter, and capture your credentials
Get-PnPRecycleBinItem to view the Recycle Bin which will show some files
• Then run
Get-PnPRecycleBinItem | Export-Csv C:\recyclebinrestore.csv to export the information to an Excel document.
• In Excel, the document will look like the below:
• Data will be exported into a CSV file. Once there, select the first column can perform the ‘Text to Columns’ option and separate by Comma.
• Select Delimited
• Select Comma, then Finish.
• Your Document will then be neatly formatted.
The full code is displayed below: