logo
search
Deleted File Recovery

Export SharePoint Recycle Bin to CSV using PnP PowerShell

Emma BrownEmma Brown Sep 28, 2026 868 views

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.

Export SharePoint Recycle Bin Files to CSV with PowerShell
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.
Before you start

Ensure you have PowerShell 7 installed on your machine and that you possess Site Collection Administrator or SharePoint Administrator privileges for the target site.

Solution 1Recommended

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.

1
Install the PnP PowerShell module

Open PowerShell 7 as an administrator and run the command: Install-Module PnP.PowerShell -Scope CurrentUser.

2
Import the module

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.

3
Connect to your SharePoint site

Authenticate to your SharePoint environment by running: Connect-PnPOnline -Url https://yourtenant.sharepoint.com/sites/yoursite -Interactive.

4
Export the Recycle Bin items to CSV

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.

Second-Stage Recycle Bin: To export items from the second-stage Recycle Bin, simply replace the '-FirstStage' parameter with '-SecondStage' in the final export command.
Free Microsoft Office alternative

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. 1. Install WPS Office: Download and install WPS Office for free on your PC or Mac.
  2. 2. Open WPS Spreadsheet: Launch the application and select the Spreadsheet module.
  3. 3. View your SharePoint data: Click Menu > Open, and select your newly exported RecycleBin.csv file to analyze your deleted SharePoint files.
Fully compatible with Microsoft Excel (.csv, .xlsx, .xls) file formatsPowerful data filtering and sorting tools to easily manage thousands of exported SharePoint recordsFree and lightweight with a familiar, tabbed user interfaceSeamless migration with no learning curve required
microsoft office alternative - wps office

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.