Add web template to available web templates

02/08/2012 14:09

$siteUrl="http://fln.blogs/"
$templateName="Cham Blogs"

$site=get-spsite $siteUrl
$web=$site.Rootweb

#create object web template collection
$NewWebTemps = New-Object System.Collections.ObjectModel.Collection[Microsoft.SharePoint.SPWebTemplate]

#get all available web templates
$existingWebTemplates=$web.GetAvailableCrossLanguageWebTemplates()| foreach-object { $NewWebTemps.Add($_) }

#get new template from site
$NewTemplate = $site.GetWebTemplates("1033") |where {$_.Title -eq $templateName}

#enable this template on web
$NewWebTemps.Add($NewTemplate);

$web.SetAvailableCrossLanguageWebTemplates($NewWebTemps)

#apply change to web
$web.update()

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