SharePoint WebTemplate
Apply SharePoint Online template using PnP PowerShell
In this article we will define a template, and apply it for other SPO sites using PnP library
Please follow these steps :
-
- Set-up PnP module latest version from here https://github.com/SharePoint/PnP-PowerShell/releases
- Go to your SPO tenant, and create a SPO Site, you can also define (List structure, Theme, Pages, Content Types) because all of those will be part of the template.
- Make sure that the app catalog is activated on the tenant (There is no relation between app catalog and the tenant, but there is a bug found in January PnP package that required App catalog to be activated or a failure occurred)
- After having the site ready, run the below PowerShell command:
$Creds = Get-Credential
$SiteURL = "https://test.sharepoint.com/sites/demo1/"
Connect-PnPOnline -Url $SiteURL -Credentials $Creds
Get-PnPProvisioningTemplate -Out C:\temp\demo1Template.xml
- You should see a progress running for a while to export all settings.
- Please open the XML file at the provisioned path (C:\temp\demo1Template.xml), and have a look, it is also doable to do medications through the file, by adding items, or fields, but you need to be careful not to crap the schema.
- Now it is time to import it to the destination site, Create a destination site on SPO with a default teamsite template
- Apply the new template by running the below command.
$DestUrl = "https://test.sharepoint.com/sites/destination1/"
Connect-PnPOnline -Url $DestUrl -Credentials $Creds
$template = Load-PnPProvisioningTemplate -Path "C:\temp\demo1Template.xml"
Apply-PnPProvisioningTemplate -InputInstance $template
After this, refresh the destination site, and you should see the template applied.
I suggest to start first with a simple template, then apply more complexity to it. this approach should run smoothly also with SP2016, but I haven’t tried to import a template from SPO and import it to 2016 or vise versa