Create web site from Custom Template in SharePoint 2010 with powershell and STSADM commands

There are many questions about creating SharePoint 2010 Web from a custom  site template saved from UI – “Save site as template”. In previous SharePoint  versions, site was saved as STP file, installed with stsadm addtemplate  cmd, then we could find its ID with stsadm enumtemplates cmd,  and create the web once again with stsadm creatweb using the template  with that ID. But in SharePoint 2010 some of this command are  deprecated, like enumtemplates. Also site templates are not stored as STP files.  Instead we save the site template as Solution, WSP.

I tried to overcome this issue, but it is now possible only trough  PowerShell. Here are the steps:

  1. Open some site collection. Create sub Web. Add some test  Document   Library. Go in Site Settings and click “SubWebTemplate”. Give   site template a name (a propose to give “File Name” and “Template Name”   without special characters and blank spaces,  you can always give more   appropriate Description). Lets say we name it SubWebTemplate.   Now you can go to Solution Gallery and view the solution/template as Activated
  2. Test your SubWebTemplate, and create another sub Web   trough user interface in order to verify that created template is OK. If so,
  3. Execute SharePoint 2010 Management shell on the Server
  4. Now we have to enumerate site templates in order to find our custom   template ID. In my case, I created web template from a sub web   sub1 in the site collection   http://sps2010/sites/webtemplate. I named (saved) my template   as SubWebTemplate
    execute this script in PowerShell   to find its ID
    $url = “http://sps2010/sites/webtemplate”   $site= new-Object Microsoft.SharePoint.SPSite($url ) $loc=   [System.Int32]::Parse(1033) $templates= $site.GetWebTemplates($loc)   foreach ($child in $templates){    write-host $child.Name   ”  ” $child.Title} $site.Dispose()
    so at the end of   this script you can see custom template ID which differs from default ones   because it starts with GUID identifying solution ID (Web Templates in 2010 are   saved as WSP – Solutions) In my case it was   {E6BD7EFF-8336-4975-BA22-2256970781E2}#SubWebTemplate  
  5. Once again, you must use PowerShell to create Web, but you can not apply   this template on creation, because it is not one of the default farm   templates. I created sub web with url sub3 and do not applied template at this   moment $web = New-SPWeb http://sps2010/sites/webtemplate/sub3  
  6. Our web is created and we have it in PowerShell variable $web. Now we will   apply our custom template to the web   $web.ApplyWebTemplate(“{E6BD7EFF-8336-4975-BA22-2256970781E2}#SubWebTemplate”)

Now we can open our create web http://sps2010/sites/webtemplate/sub3 and  verify that it is created from the site template with the test Document  Library.

Also, once we know the site template ID we can use stsadm createweb cmd to create sub web from the  template: stsadm -o createweb -url  http://sps2010/sites/webtemplate/sub4 -sitetemplate  “{E6BD7EFF-8336-4975-BA22-2256970781E2}#SubWebTemplate”

Source: MK SharePoint UG


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: