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

Terry Chan 51 Reputation points
2021-03-25T09:06:38.523+00:00

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

SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,799 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Allen Xu_MSFT 13,776 Reputation points
    2021-03-26T07:16:42.677+00:00

    Hi @Terry Chan ,

    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.