2

I want to set "subsites can only use the following site templates" radio button true in settings > Page Layout and Site Templates how to do this process in powershell?

1 Answer 1

2

Try this script

 $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 

at $templateNamesToKeep define the template that you need to only use for subsites.

For more details check Set PageLayouts and Site Templates Settings in SharePoint 2013 using PowerShell

4
  • When I added custom template to the $templateNamesToKeep Its not working. custom site template look like "CustomTemplate#CA18553C-D520-4E1D-8FD4-E57CCF24AA36" Nov 18, 2016 at 6:00
  • are you sure it's the custom template it should like "{YOUR GUID}#TemplateName" Nov 18, 2016 at 15:59
  • Oh .. Sorry I Interchanged that thing Nov 18, 2016 at 16:20
  • Please try this and tell me the result :) Nov 18, 2016 at 16:26

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.