How to Bulk Restore SharePoint Recycle Bin Files Using PowerShell
Question details
The user needs to recover thousands of deleted files from a SharePoint site's recycle bin but encounters a command-not-found error when attempting to run Connect-SPOService.
- Product
- SharePoint Online / PowerShell
- Device & OS
- not provided
- Scenario
- Attempting to perform a bulk recovery of accidentally deleted items from a SharePoint recycle bin using PowerShell scripts.
- Observed behavior
- Running the Connect-SPOService cmdlet returns a 'command not found' error, completely blocking the execution of the restore operation.
Verify that you have SharePoint Administrator privileges and that your PowerShell execution policy allows the installation of remote modules.
Install the SharePoint Online Management Shell
Resolve the 'Connect-SPOService' command-not-found error by installing the official SharePoint Online PowerShell module.
The command-not-found error typically indicates that your local PowerShell environment lacks the Microsoft.Online.SharePoint.PowerShell module. This must be installed before you can connect to your tenant.
Search for Windows PowerShell in your Start menu, right-click the application, and select 'Run as administrator'.
Type the command 'Install-Module -Name Microsoft.Online.SharePoint.PowerShell' and press Enter. If prompted to trust the repository, type 'Y' and accept.
Once installed, try running 'Connect-SPOService -Url https://[yourtenant]-admin.sharepoint.com' again. Log in with your admin credentials when the authentication window appears.
Use PnP PowerShell for Bulk Restoration
Leverage the PnP PowerShell module, an open-source library that provides simpler, optimized commands specifically designed for complex SharePoint tasks like bulk restores.
Consult Microsoft Q&A or Dedicated Management Tools
If you need a highly specific custom script or prefer not to use code, consult community forums or third-party open-source interfaces.
Streamline Your Document Management with WPS Office
While recovering deleted SharePoint infrastructure requires advanced tools like PowerShell, creating and editing your daily documents shouldn't be complicated. WPS Office is a highly compatible, free alternative to Microsoft Office that offers a familiar interface, lightweight installation, and powerful built-in local backup tools to help prevent data loss in the first place.
- 1. Download and Install: Get the official free WPS Office installer from the WPS website and complete the swift installation process.
- 2. Open Restored Files: Once your SharePoint files are restored, sync them to your desktop and simply double-click them to edit seamlessly in WPS Office.
- 3. Enable Local Backup: Go to WPS Office settings and configure auto-backup intervals to ensure you never lose document progress, even if cloud sync fails.

Frequently Asked Questions
Why is the Connect-SPOService command missing on my PC?
This happens when the Microsoft SharePoint Online Management Shell is not installed in your PowerShell environment. You must download it from Microsoft or run 'Install-Module -Name Microsoft.Online.SharePoint.PowerShell' to add the necessary cmdlets.
Is there a native SharePoint cmdlet that restores the entire recycle bin instantly?
No, the standard SharePoint Online module does not have a single 'restore all' cmdlet. Administrators usually have to write a looping script using 'Get-SPODeletedSite' or rely on the PnP PowerShell module to chain 'Get-PnPRecycleBinItem' into 'Restore-PnPRecycleBinItem'.
How long are deleted files kept in the SharePoint recycle bin?
SharePoint retains deleted files for a total of 93 days. If they are removed from the user's first-stage recycle bin, they are held in the second-stage (site collection) recycle bin for the remainder of that 93-day window before permanent deletion.
Do I need Global Administrator rights to use PnP PowerShell?
Not necessarily. While tenant-level actions require Global or SharePoint Administrator roles, you can use PnP PowerShell to restore recycle bin items within a specific site if you hold Site Collection Administrator privileges for that site.




