WebTemplate is the new way of doing site definitions in SP2010 (see this for a good overview: http://sharepointchick.com/archive/0001/01/01/site-definitions-vs.-webtemplates.aspx).
Where you need to refer to the custom WebTemplate, you’d use the ‘{FeatureID}#WebTemplateName’ syntax, e.g:
{56C8E551-565B-482A-A038-CCC18A878607}#MyWebTemplate
I however have found that this does not work with the PowerShell New-SPWeb cmdlet (when used with the -Template parameter). You’d get the error message: WARNING: Template is not found and is not applied.
To get around this, call the New-SPWeb without the -Template parameter. Then call ApplyWebTemplate on the resulting object. E.g.:
$web = New-SPWeb $url …
$web.ApplyWebTemplate($template)
This did not work for me I get the error:
PS C:\sptemp> $web.ApplyWebTemplate($template.Name)
Exception calling “ApplyWebTemplate” with “1” argument(s): “A site template has
already been applied to this site. Once a template has been applied, the site
must be deleted and recreated in order to apply a different template.”
At line:1 char:22
+ $web.ApplyWebTemplate <<<< ($template.Name)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Hiya, I am assuming you are calling this in a 2-steps process as described in this post? If so, can you try running the 1st step first, then browse to the site, do you then get the pick a template to apply page? This will test that a template has not already applied to your site.
Hey! I also have this problem. I need to apply my template ID to many different sites in my PowerShell script. But it doesen’t work. I’ve tried to do as in your post. I took away -template parameter from new SP-Web. And my sites are created. Should I add this :
$web = New-SPWeb $url …
$web.ApplyWebTemplate($template)
Should I add that to my script or should i do a new script, I’ve tried both but i don’t get it to work.
So my question really is, Where to put the “code” and do I write it wrong (syntax).
Thanks!
You should not need a separate script. When you say it does not work, did you get any error? Also, what is the value of the $template variable?