Monday, September 2, 2013

How to Hide Site Templates in SharePoint with PowerShell

How to hide a site template in SharePoint ? Editing "webtemp.xml" file is one option to hide site templates in SharePoint 2007 as per my another article: Hide Site templates & List Templates in SharePoint

However, There is an another way to hide site templates in SharePoint 2010: Using PowerShell! Update "WebTemplates" property of SPWeb object. Say for E.g. The below script sets available web templates to "Team sites" and "Blog". All others will be removed!

$Web = Get-SPWeb "http://sharepoint.crescent.com/teams/"

$Web.AllProperties["__WebTemplates"] = "<webtemplates><lcid id=""all""><webtemplate name=""STS#0"" /><webtemplate name=""BLOG#0"" /></lcid></webtemplates>"

#To Reset to Default, Use: $Web.AllowAllWebTemplates()

$Web.Update()
Just supply the site template ids to the above code to make it available. You can hide custom site templates as well. To get all available site templates, use: Get-SPWebTemplate SharePoint Site Template IDs Reference

Here is the Before and After screens:
hide site templates sharepoint 2010
After Executing the Script:
hide site template sharepoint
Hiding SharePoint site template can be achieved using C# Object model also. Manipulate SPWebTemplateCollection of SPWeb object and update it to to hide a site template in SharePoint 2010 or in SharePoint 2007.

Update: Remove Web Templates from SharePoint 2016 using PowerShell:
For SharePoint 2013 and SharePoint 2016, you can limit available site templates from site settings. Here is how:
  • Go to Site Settings >> Click on "Page Layout and Site Template Settings"
  • Set the option "Subsites can only use the following site templates" and Add templates to the right side list. 
    hide site templates in sharepoint 2016

PowerShell to hide web template in SharePoint 2013:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$SiteURL="http://intranet.crescent.com"

$Web = Get-SPWeb $SiteURL

#Get all web templates from the site
$WebTemplateCollection = $web.GetAvailableWebTemplates(1033)

#Get Team site and Blog site templates
$NewTemplateCollection = $WebTemplateCollection | where {$_.Name -eq "STS#0" -or $_.Name -eq "BLOG#0"}

#Update available web templates
$web.SetAvailableWebTemplates($NewTemplateCollection, 1033)
$web.Update()



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

2 comments :

  1. where i have to execute this code??

    As java SCRIPT or when?? please guide me on this. Thanks

    ReplyDelete
    Replies
    1. Its a PowerShell Script! Execute it using SharePoint PowerShell Management Shell or PowerShell ISE from your WFE.

      Delete

Please Login and comment to get your questions answered!


You might also like:

Related Posts Plugin for WordPress, Blogger...