Sometimes users just want to copy one piece of their site collections to other site collections. Site Designs offers you the possibility to provision an existing SharePoint list to another SharePoint site collection even in another Office 365 tenant. In this blog post, I’ll demonstrate a PowerShell-Script you can use to reach this goal. In addition. I’ll explain what is supported during provisioning.

The PowerShell command Get-SPOSiteScriptFromList makes it possible to extract an existing SharePoint list as a valid Site Script. As you already know from my other blog posts about Site Designs and Site Scripts, a Site Script is the foundation for further provisioning steps using Site Designs. In my sample scenario, a SharePoint administrator want to copy a meeting list (generic list - 100) to five other  site collections within the same Office 365 tenant. The idea here is to create SharePoint lists based on a template list which has already been set up.

Important: You may need to update your SharePoint Online Management Shell to the version 16.0. 8525.1200 or later, in order to use the demonstrated PowerShell commands below.

The PowerShell script below shows how to extract the source meeting’s list. Then it creates new Site Script and Site Design which will be temporarily used for provisioning. I used Grant-SPOSiteDesignRights to reduce the Site Design's visibility to the administrator's account only. In a foreach loop I go through the urls starting the provisioning process for each site collection using Add-SPOSiteDesignTask. Another loop takes care of checking if the Site Design task has finished for each site collection. After provisioning is complete, the Site Design and Site Script will be deleted since I want to keep the environment clean 😊


Why did I use Add-SPOSiteDesignTask instead of Invoke-SPOSiteDesign?

On the one hand, the Invoke-SPOSiteDesign command is limited to 30 cumulative actions across one or more scripts that may be called in the Site Design. It acts as a synchronous call. On the other hand, the Add-SPOSiteDesignTask command supports up to 300 cumulative actions or 100k characters. It acts as an asynchronous call. Since the command Get-SPOSiteScriptFromList also extracts components that are associated tSCRIPTa Site
Script which contains more than 30 actions. Therefore, Add-SPOSiteDesignTask is the safest way to go!

The table below shows the main differences between the commands above:

Command Operation Supported actions
Invoke-SPOSiteDesign Synchronous 30
Add-SPOSiteDesignTask Asynchronous 300

Why is Get-SPOSiteScriptFromList a powerful functionality?

This command doesn’t limit the extraction to the source list; it also extracts components associated to the list as well. For instance, if a list has site columns, it will also extract the Site Script for these site columns. If the list is associated to the left navigation, it will extract the Site Script for the navigation association. If the list has a lookup field which points to another list, it will extract the other list as well. After running this command, you have a fully configured Site Script which you can use for further provisioning steps with Site Designs.

What can you expect in May 2019 to be extracted?

The list below shows components that are supported while extracting a Site Script from an existing list using Get-SPOSiteScriptFromList.

Component Supported?
Content Types Yes
List columns Yes
Site columns Yes
Views Yes
Link to list in Quick Launch Yes
Associated extensions No (But it seems to be a bug since Get-SPOSiteScriptFromList configures the corresponding installSolution action with the SPFx extension's clientSideComponentId. Therefore, installation fails. Fix it by replacing the clientSideComponentId with the correct app id which you can retrieve using Get-PnPApp.)
List items No
User Custom Actions No
Remote Event Receiver No
Role Assignments No
Webhooks No
Workflows No

How to provision the unsupported components as well?

PnP Core is a free site provisioning framework which you can integrate with Site Designs via Microsoft Flow and Azure Function to enlarge provisioning range. Here you find the latest PnP-Schema documentation that explains the supported components. Chris O'Brien wrote a step by step guide about connecting Site Designs with PnP using a C# Azure Function. Check out his blog post to learn how to carry out this integration.

Summary

It's common to hear that developers are strategically lazy. Site Designs are also there to support our lazy skill :) because with it you can create your SharePoint list once and replicate it depending on your needs. Less code, less frustration!