Powershell: Update "Subsite Templates" under AreaTemplateSettings.aspx

Hi,

This time I am discussing about how one can update the "AvailableWebTemplates" once you have created a site. Just for the information, we can define this property in Onet.xml while creating any new site. But what if you have created sites, sub sites underneath and sub sub sites underneath, in that case you need a power shell script to update all those values.

Background: This property is defined in Onet as shown below:

<Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416">

-----------------

<Property Key="AvailableWebTemplates" Value="*-CMSPUBLISHING#0;*-BLANKINTERNET#2;*-ENTERWIKI#0;*-SRCHCEN#0"/>

---------------------

</Feature>

But once site is created using this site template, we have to dig down to update this. Using power shell its quite easy task provided you must know the Id and template name.

Work Arround:

We using the below mention code we can override the web template property. In order to update that we must know the name of template which we want to update its like CMSPUBLISHING#0 ,it follows the rule of <template name>#<configuration id>. How to get the web template

So after that run the following code in power shell:

$url = 'http://sgtspweb01/'

$SPSite = Get-SPSite -Identity $url

foreach ($SPWeb in $SPSite.AllWebs)
{
$SPWeb.AllProperties["__WebTemplates"] = '<webtemplates><lcid id="all"><webtemplate name="CMSPUBLISHING#1" /><webtemplate name="CMSPUBLISHING#0" /></lcid></webtemplates>'
$SPWeb.Update();
$SPWeb.Dispose();

write-host "Template '" $templateName "'succesfuly added to web on " $SPWeb.Url
}

Notice that "__WebTemplates" property stores the value in the xml template, so sometimes you have to just add one template then you must get the existing value of the property first then update it with the desired one.

Some times you may need to know the site template of the existing site. The code to get the title and Id of web template for any site is as follows:

$web = Get-SPWeb http://portal
write-host "Web Template:" $web.WebTemplate " | Web Template ID:" $web.WebTemplateId
$web.Dispose()

Hope that helped you.

Happy SharePointing :)...

Comments

Popular posts from this blog

Hide Ribbon on SharePoint 2013 using CSS

Get Comment Count in SharePoint

Configure external site as content sources in sharepoint search