Home Contact

The Frog Pond of Technology

Ripples of Knowledge for SharePoint and Other .Net Technologies

News

My blog has moved to WordPress at BrianTJackett.com. Any pages will automatically redirect to the new address in 7 seconds. Please excuse an issues during this migration.

 Subscribe to this blog


About Me

Name:
Brian T. Jackett
Location:
Columbus, OH
Company:
Microsoft

Find me on...

Tag Cloud


Archives

Image Galleries

Syndication:

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).

 

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018

# 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


Tuesday, March 4, 2014 12:52 AM

Feedback

No comments posted yet.


Post A Comment
Title:
Name:
Email:
Comment:
Verification: