PowerShell Script to Limit SharePoint Site Templates Available

   I had a customer request recently to limit the which site templates were available to end users to create subsites.  Below is a short PowerShell script to do just that.

 

Problem

   If you are using a Publishing Site you can restrict the available site templates by going to Site Settings –> Look & Feel and clicking on Page Layouts and Site Templates (see following screenshot).  If you are not on a Publishing Site then there is not an easy (supported) way to accomplish this through out of the box means.

LimitSPSiteTemplates1

 

Solution

   The SPWeb class has methods GetAvailableWebTemplates and SetAvailableWebTemplates that can be used in conjunction with each other to get the current list of templates and then filter down to only the desired templates.  The filtered down results can then be set and updated on the SPWeb.  A version of this script can be downloaded from the TechNet Script Repository: Limit available web templates for a SharePoint site.

Note:  Be sure to modify the “<URL of site>” to your site’s URL and also change which templates to keep (line 2).

 

# array of template names (not titles) to keep 
$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 

   Before you run the script you will see the original list of available web templates when creating a subsite.

LimitSPSiteTemplates2

 

   After you run the script you will now see only the templates which you listed in the templates to keep.

LimitSPSiteTemplates3

 

   If you need to reset the list of available web templates you can execute the AllowAllWebTemplates method on the SPWeb object.

 

Conclusion

   I had run across a few other samples for limiting web templates that involved modifying out of the box SharePoint files (changes which may be overwritten by future updates or patches, and thus not recommended).  This process of using the SetAvailableWebTemplates() method appears to be a bit more safe and supported.

 

      -Frog Out

2 thoughts on “PowerShell Script to Limit SharePoint Site Templates Available

  1. Hi Brian,
    Thanks for the solution. However it seems this only works at the first subsite creation, when we try to create a subsite inside subsites, it still displays other OOTB site teplates along with custom tab. Could you please help fix this as well

    Regards,
    Akshay65

    Like

    • Akshay65,
      Correct this solution will only apply to the site you run the script against. To also work on subsites of the original site you would need to run the script against those subsites as well. I’m not aware of an automatic way to apply.

      Like

Leave a comment