SharePoint 2016: Export all first and second stage recycle bin contents to a single File
No need to use looping to export the contents of all end user recycle bins and the second-stage recycle bin to a CSV file - a single line of PowerShell will do:
(Get-SPSite -Identity "[your site collection URL]").RecycleBin | Export-CSV -Path "[file path and name]"
This export includes all recycle bin item properties. For a listing of these properties, see the Notes section below. What's useful about this export is that you can sort and filter by recycle bin state (first or second), web name, directory name, and so on, enabling you to quickly review deleted items and their state across the site collection.
If you would rather print to the shell, a single line of PowerShell is again all that you need:
(Get-SPSite -Identity "[your site collection URL]").RecycleBin | Sort-Object -Property LeafName | Select-Object -Property Web, DirName, LeafName | Format-Table -auto
which can be condensed to the following:
(Get-SPSite -Identity "[your site collection URL]").RecycleBin | Sort LeafName | Format-Table Web, DirName, LeafName -auto
References
Notes
- Works for SharePoint 2010 and 2013 too.
- Here are all of the properties of each item in the recycle bin:
- Author
- AuthorEmail
- AuthorId
- AuthorName
- DeletedBy
- DeletedByEmail
- DeletedById
- DeletedByName
- DeletedDate
- DirName
- ID
- ImageUrl
- ItemState
- ItemType
- LeafName
- ProgId
- Size
- Title
- Web