SharePoint Online - PnP PowerShell - Recycle Bin Items

Daniel Chee 251 Reputation points
2022-07-22T06:16:18.74+00:00

Dear MS Q&A,

Seeking advice and information if there are any recommended PowerShell PnP cmdlets or scripts to inspect further information on deleted items within Recycle Bins to gather additional deleted Item details (e.g. additional item metadata to help determine and locate required deleted items) before restoring them?

----------

Example:
The Get-PnPRecycleBinItem PowerShell PnP cmdlet is used to retrieve list of deleted items but it only expose summary details of the deleted item (e.g. Title, LeafName, DeletedBy details, DirName to indicate where it was deleted from, etc...)

Are there options to determine additional deleted Item metadata (e.g. item created and modified date, additional column field values) from the retrieved results and help identify the right item to restore rather than attempting to make best guess and restore multiple deleted items as an attempt to determine which ones were the correct one?

----------

In some cases, the Title and LeafName are not sufficient enough to help determine the required item to restore.

Example Scenario:
A separate custom Reference ID column may be introduced and used commonly by users to identify items and the default Title column are either used for comments or description nature instead or may not not be used instead.
Users will quote the custom Reference ID column details to request assistance to restore deleted items but this column information is not available when reviewing the Recycle Bin items.

Thank you and appreciate any advice or information.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,127 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,444 questions
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 33,176 Reputation points Microsoft Vendor
    2022-07-25T07:18:12.457+00:00

    Hi @Daniel Chee
    For RecycleBinItem properties, there is only author properties. There is no such properties such as created and modified date. The items in Recycle Bin don't contain the column in their lists before they are deleted. I feel regretful to inform you that it turns out to be a by-design one. The items in Recycle Bin comes from different lists and they all have different columns. If they all have their custom columns in Recycle Bin. The list will run into a mess. So RecycleBinItem only have following properties in the document
    https://learn.microsoft.com/en-us/previous-versions/office/sharepoint-csom/ee536442(v=office.15)

    Since we are unable to use custom id, I will recommend you to use the guid in RecycleBinItem

    Get-PnPRecycleBinItem | Select Title, ID, ItemType, Size, ItemState, DirName, DeletedByName, DeletedDateLocalFormatted | Format-table -AutoSize  
    

    You can also recover multiple items refer to following script

    #Get All Items deleted from a specific path or library - sort by most recently deleted  
    $DeletedItems = Get-PnPRecycleBinItem | Where { $_.DirName -like "$DirPath*"} | Sort-Object -Property DeletedDate -Descending  
       
    #Restore all deleted items from the given path to its original location  
    ForEach($Item in $DeletedItems)  
    {  
        #Get the Original location of the deleted file  
        $OriginalLocation = "/"+$Item.DirName+"/"+$Item.LeafName  
        If($Item.ItemType -eq "File")  
        {  
            $OriginalItem = Get-PnPFile -Url $OriginalLocation -AsListItem -ErrorAction SilentlyContinue  
        }  
        Else #Folder  
        {  
            $OriginalItem = Get-PnPFolder -Url $OriginalLocation -ErrorAction SilentlyContinue  
        }  
        #Check if the item exists in the original location  
        If($OriginalItem -eq $null)  
        {  
            #Restore the item  
            $Item | Restore-PnpRecycleBinItem -Force  
            Write-Host "Item '$($Item.LeafName)' restored Successfully!" -f Green  
        }  
        Else  
        {  
            Write-Host "There is another file with the same name.. Skipping $($Item.LeafName)" -f Yellow  
        }  
    }  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    3 people found this answer helpful.

0 additional answers

Sort by: Most helpful