When a SharePoint Online site is deleted, it moves to the SharePoint Admin Center Recycle Bin and remains there for 93 days before permanent deletion. During this period, administrators can restore the site using PnP PowerShell.
This guide will cover:
✔ Checking the deleted sites in the recycle bin
✔ Restoring a deleted SharePoint Online site
✔ Verifying successful restoration
Step 1: Install and Connect to SharePoint Online
Ensure you have PnP PowerShell installed:
Install-Module -Name PnP.PowerShell -Force -AllowClobber
Update the module if needed:
Update-Module -Name PnP.PowerShell
Now, connect to SharePoint Online using the SharePoint Admin URL:
Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -Interactive
✔ Uses interactive login to authenticate securely.
Step 2: List Deleted SharePoint Online Sites
To view all deleted sites in the Recycle Bin, use:
powershellCopyEditGet-PnPTenantRecycleBinItem | Select-Object Url, DeletionTime
✔ Lists deleted sites and their deletion timestamps.
Step 3: Restore a Deleted SharePoint Online Site
Find the site URL and restore it using:
$siteUrl = "https://yourtenant.sharepoint.com/sites/SiteToRestore"
Restore-PnPTenantRecycleBinItem -Url $siteUrl
Write-Host "Site restored successfully: $siteUrl"
✔ Brings the deleted site back to active status.
Step 4: Verify Site Restoration
Confirm the site is restored by running:
Get-PnPTenantSite -Url $siteUrl
✔ If the site appears, it means restoration was successful.
Step 5: Restore All Deleted Sites (Bulk Restore)
To restore all deleted sites at once:
$deletedSites = Get-PnPTenantRecycleBinItem
foreach ($site in $deletedSites) {
Restore-PnPTenantRecycleBinItem -Url $site.Url
Write-Host "Restored: $($site.Url)"
}
✔ Useful when multiple sites were accidentally deleted.
Step 6: Automate Site Recovery with Task Scheduler
- Save the script as
RestoreSites.ps1
. - Open Task Scheduler → Create Basic Task.
- Set Trigger → Daily or Weekly.
- Set Action → Start a Program.
- Use this PowerShell command:
-ExecutionPolicy Bypass -File "C:\Scripts\RestoreSites.ps1"
✔ Ensures automated recovery of deleted sites.