Export SharePoint Recycle Bin to CSV using PnP PowerShell
Question details
A SharePoint administrator needs to export a list of thousands of deleted files from the Recycle Bin to a CSV file but encounters an error with the PnP PowerShell command.

- Product
- SharePoint Online
- Device & OS
- not provided
- Scenario
- Documenting and managing thousands of deleted items in a SharePoint environment by exporting the Recycle Bin data.
- Observed behavior
- The user installed PnP PowerShell, but the system throws an error stating that 'Connect-PnPOnline' is not recognized as a name of a cmdlet, function, script file, or operable program.
Ensure you have PowerShell 7 installed on your machine and that you possess Site Collection Administrator or SharePoint Administrator privileges for the target site.
Install and Configure PnP PowerShell to Export Recycle Bin Data
Use this recommended method to properly install the PnP PowerShell module, resolve the unrecognized command error, and export your deleted files to a CSV.
The 'Connect-PnPOnline is not recognized' error typically occurs when the PnP PowerShell module is not installed in the correct scope or has not been imported into the active PowerShell 7 session.
Open PowerShell 7 as an administrator and run the command: Install-Module PnP.PowerShell -Scope CurrentUser.
Make the commands available in your current session by running: Import-Module PnP.PowerShell. You can verify it by typing Get-Module -ListAvailable PnP.PowerShell.
Authenticate to your SharePoint environment by running: Connect-PnPOnline -Url https://yourtenant.sharepoint.com/sites/yoursite -Interactive.
Run the following command to retrieve first-stage Recycle Bin items and export them: Get-PnPRecycleBinItem -FirstStage | Select Title,DeletedDate,Url | Export-Csv C:\Temp\RecycleBin.csv -NoTypeInformation.
Alternative: Use SharePoint REST API or CSOM
If you cannot use PnP PowerShell due to environment restrictions, you can utilize the SharePoint REST API or CSOM scripts.
View and Analyze Your Exported CSV Files with WPS Office
After successfully exporting thousands of SharePoint Recycle Bin records, you will need a robust spreadsheet application to open, view, and analyze your CSV file. WPS Office provides a lightweight, highly compatible, and free alternative to Microsoft Office.
- 1. Install WPS Office: Download and install WPS Office for free on your PC or Mac.
- 2. Open WPS Spreadsheet: Launch the application and select the Spreadsheet module.
- 3. View your SharePoint data: Click Menu > Open, and select your newly exported RecycleBin.csv file to analyze your deleted SharePoint files.

Frequently Asked Questions
Why is the Connect-PnPOnline command not recognized?
This error occurs if the PnP.PowerShell module is not installed, not imported into your active session, or if you are using an older Windows PowerShell instead of PowerShell 7. Ensure you run 'Import-Module PnP.PowerShell' before connecting.
How do I export items from the second-stage SharePoint Recycle Bin?
In your PnP PowerShell script, modify the retrieval command by replacing the '-FirstStage' parameter with '-SecondStage' when running the Get-PnPRecycleBinItem cmdlet.
Do I need special permissions to export the SharePoint Recycle Bin?
Yes, you must have Site Collection Administrator or SharePoint Administrator privileges to access and export the complete list of Recycle Bin items across the SharePoint site.
How can I verify if the PnP PowerShell module is installed?
Open your PowerShell terminal and run the command 'Get-Module -ListAvailable PnP.PowerShell'. This will list the module if it is installed and recognized on your system.




