Restore items from recycle bin in SharePoint Online
- Git
- PowerShell
- PowerShell module: Microsoft.Online.SharePoint.PowerShell
- PowerShell module: SharePointPnPPowerShellOnline
- Microsoft 365 tenant
- Account with SharePoint Administrator privileges
If you are using PowerShell 5.0 or newer, you can install the SharePoint Management Shell from the PowerShell Gallery by using the following command:
Install-Module -Name Microsoft.Online.SharePoint.PowerShell
Import-Module -Name Microsoft.Online.SharePoint.PowerShell
If you are using PowerShell 5.0 or newer, you can install the PnP PowerShell module for SharePoint Online from the PowerShell Gallery by using the following command:
Install-Module -Name SharePointPnPPowerShellOnline
You can check if your configuration is already done:
$ git config --list
Git is writing the name and the email address into each commit command. For this you have to configure these information once in your git config file:
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
This script was build because of a misconfiguration of a deletion policy and a lot of items was deleted by a task job. The items must be restored from the recycle bin of each SharePoint Online site. A CSV file must be provided with all effected sites to check the recycle bin. With the parameter RestoreFiles you can define to get as an output only the identified items or you can also trigger the restore of these items.
Restore-SPORecycleBin -Organisation <Org Name> -MSTeamsSitesCSV <Path of CSV file with all SPO sites to check> -CSVReport <Path of the report> -RestoreFiles $true
Please read release-notes.md for details on getting them.
I use SemVer for versioning. For the versions available, see the tags on this repository.
- Stefan Gericke - Initial work - stefan@gericke.name
- Microsoft Docs: Get-PnPRecycleBinItem
- Microsoft Docs: Restore-PnpRecycleBinItem