This information is scattered online. However, I could not find this in a single place.
Imagine you like a subsite in your site collection. You save that as a template. And then you want to create new sites off of that template. It is easy to accomplish this from the GUI. However, what if you have to create 100’s of sites from the same custom template. We need a script.
It is easy to find the site templates that are available across the farm. You will use Get-SPWebTemplate. However, how to find out the custom site templates inside your site collection?
Here is how:
$webTemplates = $mySite.GetWebTemplates(1033) # I would think 1033 stands for English
$myWebTemplate = $webTemplates | ?{$_.Title -eq “Your Template Name”}
Where $mySite is the reference to your site collection inside which you created your site template.

Once you have the reference  to the template, rest of the task is easy. Just create a new web. And the apply the above template.
$myNewWeb = New-SpWeb $url -Name $siteName -UniquePermissions
$myNewWeb.ApplyWebTemplate($myWebTemplate.Name)

Advertisements