Create SharePoint Online site based on .wsp template file via PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-1567015%22%20slang%3D%22en-US%22%3ECreate%20SharePoint%20Online%20site%20based%20on%20.wsp%20template%20file%20via%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1567015%22%20slang%3D%22en-US%22%3E%3CP%3EDear%20community%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20find%20the%20quickest%20solution%20to%20provision%20new%20SharePoint%20sites%20based%20on%20a%20template%20site%20(we%20extracted%20the%20.wsp%20file).%20Currently%20we%20manually%20create%20a%20SharePoint%20site%20via%20the%20SharePoint%20Online%20admin%20center%20in%20Office%20365%20and%20create%20a%20site%20with%20the%20option%20%22select%20template%20later%22.%20After%20the%20site%20is%20created%20we%20manually%20upload%20the%20.wsp%20template%20file%20to%20the%20solution%20library%20of%20the%20new%20site%20in%20order%20to%20activate%20the%20template.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20I%20work%20for%20a%20company%20with%20%2B%2015.000%20employees%2C%20we%20are%20trying%20to%20implement%20more%20efficient%20processes%20and%20if%20possible%20automate%20standard%20processes.%20The%20manual%20process%20we%20currently%20use%20takes%20too%20much%20time%20for%20our%20support%20departments.%20I%20know%20that%20there%20is%20a%20possibility%20to%20create%20a%20SharePoint%20site%20via%20PowerShell%20and%20I%20also%20saw%20a%20PowerShell%20command%20to%20upload%20a%20.wsp%20file%20to%20a%20SharePoint%20site%2C%20however%20that%20was%20a%20PowerShell%20command%20meant%20for%20(an%20on%20premise)%20SharePoint%20Server%202013.%20Is%20there%20anyone%20who%20can%20help%20me%20with%20the%20PowerShell%20script%20to%20automate%20the%20following%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1)%20Create%20a%20SharePoint%20Online%20site%20with%20the%20option%20to%20activate%20a%20template%20later%20based%20on%20a%20locally%20(or%20virtually%20would%20be%20even%20better)%20stored%20.wsp%20file.%3C%2FP%3E%3CP%3E2)%20Upload%20the%20.wsp%20file%20to%20the%20solution%20gallery%20of%20the%20just%20created%20SharePoint%20site%3C%2FP%3E%3CP%3E3)%20Activate%20the%20template%20on%20the%20new%20SharePoint%20site%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20would%20be%20a%20tremendous%20help%20for%20us%2C%20so%20I%20hope%20you%20can%20help.%20Thank%20you%20in%20advance%20for%20thinking%20along!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKind%20regards%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESylvester%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1567015%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESites%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ETemplate%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1567313%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20SharePoint%20Online%20site%20based%20on%20.wsp%20template%20file%20via%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1567313%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F5628%22%20target%3D%22_blank%22%3E%40Matti%20Paukkonen%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20quick%20response!%20I%20had%20a%20go%20with%20your%20script%20and%20got%20it%20working.%20I%20first%20had%20an%20%22forbidden%22%20error%20when%20trying%20the%26nbsp%3BApply-PnPProvisioningTemplate%2C%20but%20I%20figured%20out%20that%20you%20had%20to%20be%20an%20administrator%20of%20the%20site%20in%20order%20to%20run%20the%20cmdlet%20(even%20though%20I%20was%20logging%20in%20with%20my%20admin%20account)%20so%20I%20worked%20passed%20that.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%2C%20what%20I%20noticed%20is%20that%20the%20images%20used%20for%20the%20landing%20page%20icons%2C%20list%20items%20created%20and%20a%20site%20page%20I%20created%20for%20the%20template%20were%20not%20taken%20along.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20you%20can%20see%20below%20-%20this%20is%20the%20original%20template%20site%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Original%20template%20site.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F210394i9A5C4801370B6608%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Original%20template%20site.png%22%20alt%3D%22Original%20template%20site.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAfter%20running%20the%20cmdlets%20in%20PnP%20PowerShell%20I%20got%20the%20following%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Site%20provisioned%20with%20PnP.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F210395i3CEA9748BC2EA673%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Site%20provisioned%20with%20PnP.png%22%20alt%3D%22Site%20provisioned%20with%20PnP.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3CP%3EIs%20there%20any%20way%20to%20get%20an%20exact%20copy%20of%20the%20original%20(with%20pictures%2C%20list%20items%20en%20site%20pages%20included)%20via%20PnP%20or%20any%20other%20way%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20help%20so%20far!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKind%20regards%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESylvester%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1567139%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20SharePoint%20Online%20site%20based%20on%20.wsp%20template%20file%20via%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1567139%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F678854%22%20target%3D%22_blank%22%3E%40Sylvester-%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20it%20required%20to%20use%20wsp-file%20approach%3F%20What%20features%20are%20required%20to%20be%20provisioned%20from%20that%20template%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBetter%20option%20would%20be%20to%20use%20PnP%20PowerShell%20to%20get%20a%20template%20out%20of%20your%20template%20site%20and%20applying%20it%20to%20a%20newly%20created%20site.%20PnP%20template%20can%20be%20exported%20to%20an%20XML%20file.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20get%20a%20template%20to%20an%20XML%20with%20PnP%20PowerShell%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EConnect-PnPOnline%20-Url%20%3CYOUR%20template%3D%22%22%20site%3D%22%22%20url%3D%22%22%3E%20-UseWebLogin%0AGet-PnPProvisioningTemplate%20-Out%20%3CPATH%20to%3D%22%22%20xml-file%3D%22%22%3E%3C%2FPATH%3E%3C%2FYOUR%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3BYou%20can%20use%20Handlers%20to%20limit%20out%20features%20you%20want%20to%20be%20included.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EApplying%20a%20template%20to%20a%20new%20site%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EConnect-PnPOnline%20-url%20%3CNEW%20site%3D%22%22%20url%3D%22%22%3E%20-UseWebLogin%0AApply-PnPProvisioningTemplate%20-Path%20%3CPATH%20to%3D%22%22%20template%3D%22%22%20xml-file%3D%22%22%3E%3C%2FPATH%3E%3C%2FNEW%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20is%20a%20link%20to%20PnP%20PowerShell%20documentation%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fsharepoint%2Fsharepoint-pnp%2Fsharepoint-pnp-cmdlets%3Fview%3Dsharepoint-ps%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fsharepoint%2Fsharepoint-pnp%2Fsharepoint-pnp-cmdlets%3Fview%3Dsharepoint-ps%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20need%20help%20with%20PnP%20templates%2C%20please%20let%20me%20know.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Dear community,

 

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!

 

Kind regards,

 

Sylvester

3 Replies

Hi @Sylvester-,

 

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. 

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:

 

Original template site.png

 

After running the cmdlets in PnP PowerShell I got the following: 

 

Site provisioned with PnP.png

 

 

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!

 

Kind regards,

 

Sylvester

 

Hi @Sylvester-

 

 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...