/commands/sharepoint-online/restore-spodeletedsite
Restore-SPODeletedSite: restore a deleted SharePoint Online site with PowerShell
- tool
- SharePoint Online PowerShell
- versions
- Microsoft.Online.SharePoint.PowerShell 16.0.27709.12000
- os
- windows
A deleted SharePoint Online site stays in the tenant's recycle bin for 93 days. To bring it back, connect with Connect-SPOService as a SharePoint Administrator, find the site with Get-SPODeletedSite, and restore it with Restore-SPODeletedSite -Identity URL. It returns at its original URL with its content and permissions.
Connect-SPOService -Url https://contoso-admin.sharepoint.com
Get-SPODeletedSite | Select-Object Url, DeletionTime, DaysRemaining
Restore-SPODeletedSite -Identity https://contoso.sharepoint.com/sites/finance
Get-SPOSite -Identity https://contoso.sharepoint.com/sites/finance | Select-Object Url, StatusReplace contoso and the site URL with your own.
The cmdlets in the module
The block lists the syntax of the recycle-bin cmdlets and the properties of a deleted-site object in version 16.0.27709.12000, then shows the error you get before connecting:
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
Get-Command Get-SPODeletedSite, Restore-SPODeletedSite, Remove-SPODeletedSite -Syntax |
Where-Object { $_.Trim() } | ForEach-Object { $_.Trim() }
'Deleted site properties: ' + ([Microsoft.Online.SharePoint.PowerShell.SPODeletedSite].GetProperties().Name -join ', ')
try { Restore-SPODeletedSite -Identity https://contoso.sharepoint.com/sites/finance -ErrorAction Stop } catch { $_.Exception.Message }Output
Get-SPODeletedSite [[-Identity] <SpoSitePipeBind>] [-Limit <string>] [-IncludePersonalSite] [<CommonParameters>] Get-SPODeletedSite [[-Identity] <SpoSitePipeBind>] -IncludeOnlyPersonalSite [-Limit <string>] [<CommonParameters>] Restore-SPODeletedSite [-Identity] <SpoSitePipeBind> [-NoWait] [<CommonParameters>] Remove-SPODeletedSite [-Identity] <SpoSitePipeBind> [-NoWait] [-WhatIf] [-Confirm] [<CommonParameters>] Deleted site properties: SiteId, Url, Status, ArchiveStatus, DeletionTime, DaysRemaining, StorageQuota, ResourceQuota No connection available. Use Connect-SPOService before running this CmdLet.
-IncludePersonalSite and -IncludeOnlyPersonalSite are in different parameter sets, so they cannot be combined. DaysRemaining tells you how long you have before the site is purged.
Variants
| Task | Command |
|---|---|
| List deleted sites | Get-SPODeletedSite -Limit All |
| Include deleted OneDrives | Get-SPODeletedSite -IncludePersonalSite -Limit All |
| Only deleted OneDrives | Get-SPODeletedSite -IncludeOnlyPersonalSite -Limit All |
| Restore one site | Restore-SPODeletedSite -Identity URL |
| Restore without waiting | Restore-SPODeletedSite -Identity URL -NoWait |
| Purge it for good | Remove-SPODeletedSite -Identity URL (cannot be undone) |
Without -NoWait the cmdlet waits until SharePoint has finished the restore; with it, the command returns at once and you check later with Get-SPOSite.
Sites connected to a Microsoft 365 group
Restoring a group-connected site (Teams, Outlook groups) restores the Microsoft 365 group and its resources too. The other group resources are kept for only 30 days, while the site is kept for 93. If the other group resources have already been deleted, Microsoft documents Remove-SPODeletedSite as the way to permanently delete the leftover site. Restore group-connected sites within 30 days to get the whole group back.
Errors
| Message | Cause |
|---|---|
| No connection available. Use Connect-SPOService before running this CmdLet. | No Connect-SPOService in this session, or it expired |
| Parameter set cannot be resolved using the specified named parameters. | -IncludePersonalSite and -IncludeOnlyPersonalSite used together |
| Cannot convert value ... to type SpoSitePipeBind | -Identity is not a site URL |
See No connection available and SpoSitePipeBind conversion. Run the module in Windows PowerShell 5.1, or in PowerShell 7 with Import-Module Microsoft.Online.SharePoint.PowerShell -UseWindowsPowerShell.
FAQ
How long can a deleted SharePoint site be restored?
93 days. After that the site, its lists, libraries, pages and subsites are deleted permanently and only a retention policy or a backup can bring the content back.
How do I restore a deleted OneDrive?
List it with Get-SPODeletedSite -IncludeOnlyPersonalSite, then run Restore-SPODeletedSite -Identity with the OneDrive URL (https://TENANT-my.sharepoint.com/personal/...).
Can I restore a site to a different URL?
Not with Restore-SPODeletedSite: its only parameters are -Identity (the URL the site had when it was deleted) and -NoWait, so the site comes back at that URL.
Sources
- learn.microsoft.comlearn.microsoft.com/en-us/powershell/module/microsoft.online.sharepoint.powershell/restore-spodeletedsite
- learn.microsoft.comlearn.microsoft.com/en-us/powershell/module/microsoft.online.sharepoint.powershell/get-spodeletedsite
- learn.microsoft.comlearn.microsoft.com/en-us/sharepoint/restore-deleted-site-collection