In this blog, we will learn how to get number of items present in recycle bin and apply different filter conditions on it. We will also see how to restore the items to its previous location.
Steps:
- First we need to connect site. We can do this following below command
Open SharePoint Online Management Shell as administrator and add
Connect- PnPOnline – Url $siteURL #Executing this line will ask for credentials. Provide use name and password to connect.
2. To get all items count present in recyclebin use below commands
(Get-PnPRecycleBinItem).count
3. To apply different filter conditions, follow below commands
A. Retrieve items from recycle bin applying filter conditions on Users
We will apply filter on the user who deleted the items added it to the first-stage recycle bin through user email address.
Get-PnPRecycleBinItem- FirstStage | ?DeletedByEmail -eq ‘user@domain.com’
B. Retrieve items from recyclebin applying filter conditions on file extensions
Get-PnPRecycleBinItem -FirstStage | ? LeafName -like ‘*.docx’
C. Retrieve items from recyclebin applying filter conditions on item title
Get-PnPRecycleBinItem | ? Title -Like ‘*DemoBook*’ | ft
4. Apply restore to items retrieved through filter conditions items title contain
Get-PnPRecycleBinItem -firststage | ? {($_.DeletedDate -gt $restoreDate) -and ($_.Title -Like ‘*DemoBook*’)} | Restore-PnpRecycleBinItem -Force
Img 1. Applying restore command
Img 2. Before applying restore command
Img 3. After apply restore command
Keywords:
• Retrieve recycle bin items using filter condition on user who deleted items.
• Retrieve recycle bin items using filter conditions on items having extension match.
• Retrieve recycle bin items using filter condition on items title matched.
• Restore items from first stage recycle bin using PNP PowerShell.
• Get no of items stored in recycle bin using PNP PowerShell.
• Restore items from recycle bin using PNP PowerShell.