Exporting SharePoint RecycleBin Items with PowerShell

Straightforward PowerShell script designed to export RecycleBin items from the SharePoint Site, utilizing PnP PowerShell.

Here’s is a simple powershell script to export RecycleBin items from the SharePoint Site by utilizing PnP PowerShell.

$siteurl = "https://<tenant_name>.sharepoint.com/sites/<site_name>"
Connect-PnPOnline $siteurl -Interactive
Write-Host "Execution Started..."
$recyclebinitems = Get-PnPRecycleBinItem -FirstStage
Write-Output "Total recyclebin items: $recyclebinitems.length"
If ($recyclebinitems.length -gt 0) {
    $results = @()
    foreach ($item in $recyclebinitems) {
        $results += [pscustomobject][ordered]@{
            ID    = $item.Id
            Title = $item.Title 
            Type  = $item.ItemType
            Path = $item.DirName
            Name = $item.LeafName
            Deleted = $item.DeletedDate
            DeletedBy = $item.DeletedByName
        }
    }
    $results | Export-Csv -Path "recycleitem.csv" -NoTypeInformation
    Write-Host "Export Completed."
}
else {
    Write-Information "No Recyclebin items found!"
}
Write-Host "Execution completed."

The above script exports the file in the current path, where you are running the script.


If you don’t have PnP PowerShell installed on your machine, run the below command,

Install-Module PnP.PowerShell -Scope CurrentUser

For more information, Installing PnP PowerShell

Shantha Kumar
Shantha Kumar
Articles: 293

Leave a Reply

Your email address will not be published. Required fields are marked *