I got a task to setup company’s hierarchy using our own custom created site template. My first priority is to achieve this task through PowerShell. Creating site collection or sub site through PowerShell is fairly a simple task, the command for creating sub site is
Ref: http://technet.microsoft.com/en-us/library/ff607579(v=office.15).aspx
I tried to replace the template name with my custom template’s name which I found out through the below script:
Add-PSSnapin Microsoft.Sharepoint.Powershell $web = get-spweb https://sharepoint $template = $web.GetAvailableWebTemplates(1033) | Where-Object {$_.Title -eq “<Custom Templete Title>”} Write-Host $template.NameIn the below script substitute the default template name with my custom template name but this didn’t work
New-SPWeb -Url “https://sharepoint/newsubsite” -Template “{D839E38A-F9DF-4B35-BDA7-A1E273C51EAB}#XXXX Template”Output:
After looking into documentation the parameter it takes as Template is SPWebTemplatePipeBind which is optional. If someone doesn’t set the template, the site will be created but the template isn’t applied which will then prompt for template selection against its first visit. Finally I came up with the below script which worked like a charm.
Add-PSSnapin Microsoft.Sharepoint.Powershell $web = get-spweb https://sharepoint $template = $web.GetAvailableWebTemplates(1033) | Where-Object {$_.Title -eq “<Custom Templete Title>”} $newweb = New-SPWeb -Url “https://sharepoint/newsubsite” $newweb.ApplyWebTemplate($template.Name)
No Comments