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:
<Property Key=”AvailableWebTemplates” Value=”*-CMSPUBLISHING#0;*-BLANKINTERNET#2;*-ENTERWIKI#0;*-SRCHCEN#0″/>
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.
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>’
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
Hope that helped you.
Happy SharePointing :)…