SharePoint Online: How to Restore a Deleted Site Collection using PowerShell?

Requirement: Restore a Deleted Site Collection in SharePoint Online.

How to Restore a Deleted Site Collection in SharePoint Online?
SharePoint Online recycle bin provides the ability to recover even when an entire site collection is deleted. To restore a deleted site collection in SharePoint Online, follow these steps:
  • Login to SharePoint Online Admin Center >> Click on "Site Collection" link in left navigation.
  • On the ribbon, Click on "Recycle Bin" button. You'll see the list of all Site Collections which are deleted along with when they were deleted, and how many days are remaining before they disappear from the recycle bin.
  • To restore deleted site collection, Select the site collection that you want to restore in the Recycle Bin page, Click on "Restore Deleted Items" button in the Ribbon 
    sharepoint online restore deleted site collection
  • Click on "Restore" button in the Popup window to restore the selected site collection.
    sharepoint online powershell restore deleted site
Similarly, to restore SharePoint Online site in modern admin center: Click on "Deleted Sites" link from the left navigation >> This page lists all deleted site collections. Pick the one you want to restore and click on "Restore" button from the ribbon. You'll get a message "Site Restored" once the restore operation completes.
restore sharepoint online site using powershell
The default retention period for deleted items in SharePoint Online is 93 days!

SharePoint Online: PowerShell to Restore a Deleted Site Collection
When a SharePoint Online site collection is deleted, it is placed in the recycle bin, then it is permanently deleted after the retention period. Recovering a SharePoint Online site is quite easy. Here is the PowerShell to restore deleted site collection.

Step 1: Connect to SharePoint Online from SharePoint Online Management Shell
#Config Parameters

#Get Credentials to connect
$Cred = Get-Credential

#Connect to SharePoint Online Tenant Admin
Connect-SPOService -URL $AdminSiteURL -Credential $Cred

Step 2: Get a List of All Deleted Site Collections
#Get All Deleted Sites

Step 3: Restore the Site collection from Recycle bin
#sharepoint online restore deleted site powershell
Restore-SPODeletedSite -Identity ""
sharepoint online powershell restore site collection
That's it. Your site should be back! We've restored SharePoint Online site collection using PowerShell. If you want to permanently delete a site collection, you have to delete it from the recycle bin as in SharePoint Online: Delete Site Collection from Recycle bin using PowerShell

Restore Deleted SharePoint Online Site using PnP PowerShell 
Let's recover deleted site collection in SharePoint Online using PnP PowerShell.
#Config Variables
$TenantURL = ""
$DeletedSiteURL =""

#Connect to PnP Online
Connect-PnPOnline -Url $TenantURL -Credentials (Get-Credential)
#Get Deleted Site from Recycle Bin
$DeletedSite = Get-PnPTenantRecycleBinItem | Where {$_.URL -eq $DeletedSiteURL}

    #restore site collection sharepoint online powershell
    Restore-PnPTenantRecycleBinItem -Url $DeletedSiteURL -Force -ErrorAction Stop
    Write-Host -f Green "Site Collection '$DeletedSiteURL' Restored Successfully!"
    Write-host -f Yellow "Could not Find Deleted site:"$DeletedSiteURL
This PowerShell restores deleted site in SharePoint Online!
SharePoint Online: How to Restore a Deleted Site Collection using PowerShell? SharePoint Online: How to Restore a Deleted Site Collection using PowerShell? Reviewed by Salaudeen Rajack on March 15, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.