How To Restore A Subsite From SharePoint Online Using PnP PowerShell

I have deleted a subsite “Subsite 001” from a site collection, which moved to the Site Collection (Second Stage) recycle bin. In this blog, you will see how to restore a subsite from the second stage recycle bin using PnP PowerShell.

Copy the below script and paste it in a notepad. Save the file as RestoreSubsite.ps1.

  1. # Input Parameters     
  2. $credentials=Get-Credential   
  3. $URL="https://c986.sharepoint.com/sites/dev/"  
  4. $title="Subsite 001"  
  5.     
  6. Connect to SharePoint Online   
  7. Connect-PnPOnline -Url $URL -Credentials $credentials  
  8.   
  9. Get-PnPRecycleBinItem | ? Title -eq $title | Restore-PnPRecycleBinItem  

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"  

folderlocation – RestoreSubsite.ps1 file location

Run the following command

  1. >.\RestoreSubsite.ps1  

Reference - Restore-PnPRecycleBinItem

Thus in this blog, you saw how to restore a subsite from SharePoint Online using PnP PowerShell.