Manage Recycle Bin And Restore

Introduction 

 
In this blog, we will learn how to get a number of items present in the recycle bin and apply different filter conditions on it. We will also see how to restore the items to their previous location.
 

Steps

 
First, we need to connect the site. We can do this following the below command.
 
Open SharePoint Online Management Shell as an administrator and add
 
Connect- PnPOnline - Url $siteURL
 
# Executing this line will ask for credentials. Provide a user name and password to connect.
 
Manage Recycle Bin and Restore
 
To get all items to count present in the recyclebin, use the below commands.
 
(Get-PnPRecycleBinItem).count
 
Manage Recycle Bin and Restore
 
To apply different filter conditions, follow the below commands.
 
Retrieve items from recycle bin applying filter conditions on Users.
 
We will apply a filter on the user who deleted the items added to the first-stage recycle bin through the user email address.
 
Get-PnPRecycleBinItem- FirstStage | ?DeletedByEmail -eq '[email protected]'
 
Manage Recycle Bin and Restore
 
Retrieve items from recyclebin applying filter conditions on file extensions.
 
Get-PnPRecycleBinItem -FirstStage | ? LeafName -like '*.docx'
 
Manage Recycle Bin and Restore
 
Retrieve items from recyclebin applying filter conditions on the item title.
 
Get-PnPRecycleBinItem | ? Title -Like '*DemoBook*' | ft
 Manage Recycle Bin and Restore
 
Apply restore to items retrieved through filter conditions items title contain.
 
Get-PnPRecycleBinItem -firststage | ? {($_.DeletedDate -gt $restoreDate) -and ($_.Title -Like '*DemoBook*')} | Restore-PnpRecycleBinItem -Force
 
Manage Recycle Bin and Restore
Img1. Applying restore command
 
Manage Recycle Bin and Restore
Img2. Before applying restore command
 
Manage Recycle Bin and Restore
Img3. After apply restore command