When a SharePoint Online site is deleted, it moves to the SharePoint Deleted Sites (Recycle Bin) and remains there for 93 days before permanent deletion. During this period, administrators can restore the site using PnP PowerShell instead of recreating it from scratch.
This guide explains how to restore a deleted SharePoint site using PnP PowerShell step by step, along with best practices, troubleshooting, and verification methods.
Prerequisites
Before you begin, ensure that you have the following:
SharePoint Admin or Global Admin Role – Required for restoration.
PnP PowerShell Installed – If not installed, install it.
Site must still be in the Deleted Sites list – Once permanently deleted, restoration is not possible.
PowerShell Execution Policy – Should allow script execution.
Step 1: Install and Import PnP PowerShell Module
If you haven’t installed PnP PowerShell, install it using the following command:
Install-Module -Name PnP.PowerShell -Scope CurrentUser -AllowClobber -Force
Then, import the module:
Import-Module PnP.PowerShell
This ensures that all required cmdlets are available for use.
Step 2: Connect to SharePoint Admin Center
To manage SharePoint Online sites, connect to the SharePoint Admin Center using PnP PowerShell:
Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -Interactive
🔹 Replace yourtenant
with your actual SharePoint tenant name.
🔹 The -Interactive
flag prompts a login window for authentication.
Alternatively, for App-based authentication:
Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -ClientId "Your-App-Client-ID" -Tenant "yourtenant.onmicrosoft.com" -CertificatePath "Path\To\Certificate.pfx"
Step 3: List All Deleted Sites
Before restoring a site, check if it’s still in the Deleted Sites list:
Get-PnPDeletedSite
This command returns a list of all deleted SharePoint sites in the tenant, including their URLs and deletion dates.
Step 4: Find the Site You Want to Restore
If you need to locate a specific deleted site, filter the list:
Get-PnPDeletedSite | Where-Object { $_.Url -like "*your-site-name*" }
Replace "your-site-name"
with a partial URL or site name to narrow the search.
If the site appears in the results, you can proceed with restoration.
Step 5: Restore the Deleted SharePoint Site
To restore a deleted site, use:
Restore-PnPDeletedSite -Identity "https://yourtenant.sharepoint.com/sites/SiteToRestore"
Replace "https://yourtenant.sharepoint.com/sites/SiteToRestore"
with the actual URL of the deleted site.
This command restores the site to its original state, including content, permissions, and settings.
Step 6: Verify the Restoration
After restoring, check if the site is available again:
Get-PnPTenantSite | Where-Object { $_.Url -eq "https://yourtenant.sharepoint.com/sites/SiteToRestore" }
If the site appears in the results, it has been successfully restored.
You can also manually check by navigating to the URL in a browser.
Step 7: Disconnect the PowerShell Session
Once you’ve restored and verified the site, disconnect the session:
Disconnect-PnPOnline
Common Errors & Troubleshooting
Error | Possible Cause | Solution |
---|---|---|
Access Denied | User lacks required permissions | Ensure you are a SharePoint Admin or Global Admin |
Site not found | Site may be permanently deleted | Run Get-PnPDeletedSite to check if it still exists |
PnP PowerShell module not found | Module not installed | Run Install-Module -Name PnP.PowerShell |
Cannot connect to SharePoint Online | Authentication issues | Use -Interactive login mode |