question

TerryChan-4994 avatar image
0 Votes"
TerryChan-4994 asked AllenXu-MSFT commented

How to create site collection based on template by powershell in SharePoint 2016?

I have saved a site template file lksfm.wsp and want to create a site collection using powershell as below. I know the Template parameter wouldn't work using lksfm.wsp. How should I handle the lksfm.wsp file before I can use it to create site collection using powershell?

New-SPSite 'https://domain/' -HostHeaderWebApplication (Get-SPWebApplication 'Workspace Home') -Name 'Workspace Home' -Description 'Workspace Home' -OwnerAlias 'domain\user' -language 1033 -Template lksfm.wsp -contentdatabase Content_DB1

office-sharepoint-server-administration
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AllenXu-MSFT avatar image
0 Votes"
AllenXu-MSFT answered AllenXu-MSFT commented

Hi @TerryChan-4994 ,

We should use internal name of a site template after parameter -Template when using New-SPSite command. This means we need to deploy the site template as a farm solution to SharePoint before executing the command. There is a detailed article about how to achieve this, please take a reference to it: How to Build a Site Collection Template from A Web Template in SharePoint 2010. Although this article is based on SharePoint 2010 environment, it works perfectly for SharePoint 2016 as per my test.

After completing this, you will find your site template can be seen under custom section on the Create Site Collection page, we need to retrieve its internal name using F12 developer tools. As shown in the below screenshot, the value of tag <option> {0A2E4A08-75F5-4184-977E-A5C9877BD466}#testTemp is the internal name of my test template( testTemp )
81831-1.png

Then I created a site collection based on the testTemp template using the below powershell.

 $template = Get-SPWebTemplate "{0A2E4A08-75F5-4184-977E-A5C9877BD466}#testTemp"
 New-SPSite 'http://sp/sites/4test' -OwnerAlias "CONTOSO\aministrator" -Template $template -language 1033 -contentdatabase WSS_Content

Hope this may help. Please feel free to let me if you have any confusion while following the steps in that article.


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1.png (33.6 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@TerryChan-4994 ,

How is everything going on this thread? I'm looking forward to your reply. If an answer is helpful to you, please remember to accept it as answer. Thanks for your understanding :-)

1 Vote 1 ·

Thanks for your solution.

0 Votes 0 ·

@TerryChan-4994

If an answer is helpful to you, you could accept it as answer.

It will be beneficial to others in this forum who meet the same issue in the future.

0 Votes 0 ·