When users delete files and folders from the SharePoint Online document library, they are moved to the first-level Recycle Bin. Files from the end-user recycle bin can be restored by any SharePoint site member. Files deleted from the first level recycle bin are moved to the second level recycle bin, which can only be accessed by site owners or administrators. After reaching the 93-day lifetime of deleted items, files in SharePoint Online’s two-stage recycle bin are automatically deleted.
In this article, we will show you how to restore all deleted items using the SharePoint Online web Interface or with PowerShell.
Restoring Deleted Items from the SharePoint Online Recycle Bin
Any SharePoint site member can recover deleted files from the first-level recycle bin of SharePoint Online. Members will be able to restore files that have been deleted by someone else.
You can recover a deleted file from the OneDrive desktop app on users’ computers (OneDrive > Recycle Bin). You will be redirected to the recycle bin page of the OneDrive website.
You can also recover a deleted item from the SharePoint web interface:
- Sign-in your SharePoint site, select Site Contents and click Recycle Bin in the left column;
- You will see a list of files and folders that have been deleted from the document library of this SharePoint site. You can sort files by the date they were deleted, by the owner, or by the person who deleted the file;
- Right-click the item you need and select Restore. Note that if a folder is deleted, you will not be able to view its contents. Even if you only need the single file in it, you must restore it in its entirety;
- The files and folders will be restored to their original location in the SharePoint library.
If the user has deleted files from the first-level recycle bin, the SharePoint site owners or administrators can access the second-level recycle bin and restore the items.
Go to Site Settings, scroll to the very bottom of the list of deleted items and click on the link for the Second-stage recycle bin.
Search and restore the item you are looking for.
Restore Delete Files from SharePoint Recycle Bin with PowerShell
An administrator can use PowerShell to get a list of deleted SharePoint Online site files and restore them from the Recycle Bin. Install the SharePoint Online (PnP) management module on your computer:
Install-Module PnP.PowerShell
Connect to your SharePoint site from the PowerShell Core console:
$siteUrl = "https://theitbros.sharepoint.com/sites/Marketing" Connect-PnPOnline -Url $siteUrl -Interactive
To get the total number of deleted items in the recycle bin of a SharePoint site, run the command
(Get-PnPRecycleBinItem).Count
View a full list of deleted items:
Get-PnPRecycleBinItem|select Title, DirName ,ItemType,DeletedDate
You can filter deleted items in the SharePoint recycle bin according to many criteria.
By item type:
Get-PnPRecycleBinItem | Where-Object { $_.ItemType -eq 'Folder' }
By file name:
Get-PnPRecycleBinItem | ? -Property LeafName -like "*2024*.pptx"
By date of deletion:
$FromDate = Get-Date("01/01/2024") $ToDate= Get-Date("01/17/2024") Get-PnPRecycleBinItem | Where {($_.DeletedDate -ge $FromDate -and $_.DeletedDate -le $ToDate)}
By user who deleted files:
Get-PnPRecycleBinItem | Where { $_.DeletedByEmail -eq "kirill@theitbros.com"}
Use the Restore-PnpRecycleBinItem cmdlet to restore a deleted object.
You can restore an item from the recycle bin by its ID:
Restore-PnPRecycleBinItem -Identity your_deleted_item_id
Or just pipe the Get-PnPRecycleBinItem result to the Restore-PnPRecycleBinItem:
Get-PnPRecycleBinItem | ? -Property LeafName -like "*2024*.pptx"| Restore-PnPRecycleBinItem
Confirm to restore the item and your file will be moved from the SharePoint recycle bin to its original location.
You can use the -FirstStage or -SecondStage parameters of the Get-PnPRecycleBinItem cmdlet to browse the user or administrative SharePoint recycle bin.