Clone or Copy SharePoint Online Site Collection With Lists Content

Modern problems need modern solution...!

Although we have spent years with SharePoint On-Premises but its time to move on SharePoint Online. Being SharePoint Administrator in past, now you may have to deal with Microsoft Cloud Admin. It was pretty easy in good old days to copy or clone a site using backup restore or using export import methods. However, that thing do not work anymore in SharePoint Online. You have to try different approach and syntax for this. There are several articles on this but I found this one which lead me to different type of errors and ultimately to the actual solution I was looking for. Here is how I did it...

There are three main components in this article.

  1. Create a Site in SharePoint online with some dummy data
  2. Use PNP PowerShell to backup the site template and list data
  3. Create new site and restore the template


Important : The commands I will be using in this article are different than the used in above mentioned article. To run these commands, you need to get rid of the legacy SharePoint PNP Online and Install the PNP PowerShell. Please see this detailed article or run the below commands.

Uninstall-Module -Name "SharePointPnPPowerShellOnline" -AllVersions -Force


Install-Module -Name "PnP.PowerShell"

1. Create a Site in SharePoint online with some dummy data

Let's create a new site for this.



Site has been created. Now lets create a list and add some items.


Add a new custom column.



Add some dummy data.


2. Use PNP PowerShell to backup the site template and list data

Run the below commands to export the template. (Full script is on the end)



3. Create new site and restore the template

Create new site is pretty easy in SharePoint Online using PNP.


Note: The syntax is different to create a modern communication site and modern team site. Check this for complete details. Also, you need to be very sure that your source and target sites templates are same. Check full details here. For example

To create Modern Team Site (Our case): 

New-PnPSite -Type TeamSite -Title 'Shadow of Teams' -Alias ShadowTeams

If you want to create Modern Communication Site:

New-PnPWeb -Title "SubSite of Modern Team s" -Url SubSiteTeams -Description "Creating Subsite of Teams" -Locale 1033 -Template "STS#3"

SharePoint Online Site Templates names:

Template IDTitleDescription / Additional Info
STS#3Team site (no Office 365 group)A site with no connection to an Office 365 Group.
SITEPAGEPUBLISHING#0Communication sitePublish dynamic, beautiful content to people in your organization to keep them informed and engaged on topics, events, or projects.
GROUP#0Office 365 Group associated Team SiteFor Reporting Only – You cannot create sites with this template
POINTPUBLISHINGPERSONAL#0Delve BlogFor Reporting OnlyDelve Blogs are being Retired
SPSPERS#10OneDrive for Business personal SiteFor Reporting Only – Use the Request-SPOPersonalSite cmdlet to pre-provision a OneDrive for Business ite
RedirectSite#0Redirect SitePlaceholder template for the old URL when you rename the Site URL. This is for reporting only and those sites are only created by Microsoft programmatically.
TEAMCHANNEL#0Teams Private Channel SiteLightweight Site Collection provisioned for each Teams Private Channel Site. This is For Reporting Only, and not for manual provisioning trough SharePoint Online



Lets verify the site now.








Complete Script

Connect-PnPOnline -interactive -URL "https://sharepointerguy.sharepoint.com/sites/ModernTeams"
Get-PnPSiteTemplate -Out "D:\Temp\MyApplications.xml"
Add-PnPDataRowsToSiteTemplate -Path "D:\Temp\MyApplications.xml" -List "Food Items"

New-PnPSite -Type TeamSite -Title 'Shadow of Teams' -Alias ShadowTeams

Connect-PnPOnline -interactive -URL "https://sharepointerguy.sharepoint.com/sites/ShadowTeams"
Invoke-PnPSiteTemplate -Path "D:\Temp\MyApplications.xml"

Bingo...!





Comments

Popular Posts

GREYCstoration Oil Paint plugin for Photoshop

Service Bus Gateway service stuck at Starting

PowerApps SubmitForm not clearing People Picker value

Apple iPhone sending SMS automatically 00447786205094

SharePoint online hub navigation not updating for other users