Aug 05 2020 03:49 AM
Aug 05 2020 03:49 AM
I am trying to find the quickest solution to provision new SharePoint sites based on a template site (we extracted the .wsp file). Currently we manually create a SharePoint site via the SharePoint Online admin center in Office 365 and create a site with the option "select template later". After the site is created we manually upload the .wsp template file to the solution library of the new site in order to activate the template.
As I work for a company with + 15.000 employees, we are trying to implement more efficient processes and if possible automate standard processes. The manual process we currently use takes too much time for our support departments. I know that there is a possibility to create a SharePoint site via PowerShell and I also saw a PowerShell command to upload a .wsp file to a SharePoint site, however that was a PowerShell command meant for (an on premise) SharePoint Server 2013. Is there anyone who can help me with the PowerShell script to automate the following:
1) Create a SharePoint Online site with the option to activate a template later based on a locally (or virtually would be even better) stored .wsp file.
2) Upload the .wsp file to the solution gallery of the just created SharePoint site
3) Activate the template on the new SharePoint site
This would be a tremendous help for us, so I hope you can help. Thank you in advance for thinking along!
Aug 05 2020 05:16 AM
Is it required to use wsp-file approach? What features are required to be provisioned from that template?
Better option would be to use PnP PowerShell to get a template out of your template site and applying it to a newly created site. PnP template can be exported to an XML file.
To get a template to an XML with PnP PowerShell
Connect-PnPOnline -Url <your template site url> -UseWebLogin Get-PnPProvisioningTemplate -Out <path to xml-file>
You can use Handlers to limit out features you want to be included.
Applying a template to a new site
Connect-PnPOnline -url <new site url> -UseWebLogin Apply-PnPProvisioningTemplate -Path <path to template xml-file>
Here is a link to PnP PowerShell documentation https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets?view=sh...
If you need help with PnP templates, please let me know.
Aug 05 2020 06:43 AM - edited Aug 05 2020 06:46 AM
Hi @Matti Paukkonen,
Thanks for the quick response! I had a go with your script and got it working. I first had a "forbidden" error when trying the Apply-PnPProvisioningTemplate, but I figured out that you had to be an administrator of the site in order to run the cmdlet (even though I was logging in with my admin account) so I worked past that.
However, what I noticed is that the images used for the landing page icons, list items created and a site page I created for the template were not taken along.
As you can see below - this is the original template site:
After running the cmdlets in PnP PowerShell I got the following:
Is there any way to get an exact copy of the original (with pictures, list items en site pages included) via PnP or any other way?
Thanks for the help so far!
Sep 22 2020 09:35 PM
Images from pages can be included by adding -PersistBrandingFiles handle to Get-PnPProvisioningTemplate. And all client-side pages can be included with -IncludeAllClientSidePages handle. For example:
Get-PnPProvisioningTemplate -Out <path to xml-file> -PersistBrandingFiles -IncludeAllClientSidePages
List items cannot be included in the template. You need to create a separate script for creating list items using Add-PnPListItem. Documentation with examples can be found here: https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/add-pnplistitem?view=sharepoint-ps...