Hide Web Template

In PowerShell, if you want to remove a web template from the New Site dialog for a specific web, take a look at the following script:

function Remove-SPWebTemplate {
	[CmdletBinding()]
	param(
		[parameter(Position=1,Mandatory=$true)][Microsoft.SharePoint.SPWeb]$web
	)
	process {
		$templateList = New-Object "System.Collections.ObjectModel.Collection``1[[Microsoft.SharePoint.SPWebTemplate, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]]"
 
		$availableWebTemplates = $web.GetAvailableWebTemplates(1033);
		$availableWebTemplates | Where{ $_.ID -ne 53 } | ForEach-Object {
		     $templateList.add($_)
		}
 
		if ($templateList.Count -gt 0) {
			Write-Host ("Removing Blank Internet web template with from web '", $_.Title, "' at ", $_.Url -join "") -NoNewline
			$web.SetAvailableWebTemplates($templateList, 1033);
			$web.Update()
			Write-Host " - Done." -ForegroundColor Green
		}
		else {
			Write-Host ("No web templates found for web ", $_.Url -join "") -ForegroundColor Red
		}
	}
}
 
Get-SPWebApplication | ForEach-Object {
	$_.Sites | Where { $_.ServerRelativeUrl -ne '/sites/example' } | ForEach-Object {
		$_.AllWebs | ForEach-Object {
			Remove-SPWebTemplate $_
		}
	}
}


Within the Remove-SPWebTemplate method a list of all currently enabled web templates is added to the templateList variable by calling the GetAvailableWebTemplates method for the web object and adding all templates that don’t match the one we want to hide. In this example, that’s the template with the ID 53 – Blank Internet.

This collection is then passed into the SetAvailableWebTemplates method to define the visible template for new sites created within the web.

In this example, the webs have been restricted to those in the site collection ‘/sites/example’.

This entry was posted in SharePoint and tagged , . Bookmark the permalink.
0 0 votes
Article Rating
Subscribe
Notify of
guest

Solve the maths problem shown below before posting: *

0 Comments
Inline Feedbacks
View all comments