2

I need to add a custom site template in site settings -> page layouts & site templates for subsites can only use the following site templates.By manuvally we can add it,how can we achieve it by using powershell scripts. please suggest some idea to achieve this?

enter image description here

2 Answers 2

2
$templateNamesToKeep = "STS#0","PROJECTSITE#0","BLOG#0"

 Start-SPAssignment -Global
 $web = Get-SPWeb <URL of site> 

 # get the existing web templates from the site that will be filtered down 
 # 1033 is the locale id for English US (en-us), be sure to change to your locale 
 $existingWebTemplates = $web.GetAvailableWebTemplates(1033) 
 $newWebTemplates = New-Object "System.Collections.ObjectModel.Collection[Microsoft.SharePoint.SPWebTemplate]"

 # filter existing web templates and only keep if in the list of template names to keep 
 $newWebTemplates = $existingWebTemplates | Where-Object {$_.name -in $templateNamesToKeep} 
 $web.SetAvailableWebTemplates($newWebTemplates, 1033) 
 $web.Update() 

 Stop-SPAssignment -Global 

Reference: Set PageLayouts and Site Templates Settings in SharePoint 2013 using PowerShell

6
  • whether we need to add the site template in ("subsites can only use the following site template section") correct me If I am wrong @BennySkogberg
    – Debugger
    Dec 13, 2016 at 10:38
  • @Suriya Sorry. I misunderstood your question as there where no image available...
    – Benny Skogberg
    Dec 13, 2016 at 10:51
  • Its okay dude, any idea to achieve this? @Benny Skogberg
    – Debugger
    Dec 13, 2016 at 11:00
  • @Suriya Yep - I've updated my answer!
    – Benny Skogberg
    Dec 13, 2016 at 11:07
  • 1
    Great, It work's like charm. Thank you so much @BennySkogberg
    – Debugger
    Dec 13, 2016 at 11:14
1

Using below powershell script you can apply custom template to subsite.

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.