{"id":1568,"date":"2013-10-19T17:47:22","date_gmt":"2013-10-19T16:47:22","guid":{"rendered":"http:\/\/www.stuartroberts.net\/?p=1568"},"modified":"2013-11-11T15:54:59","modified_gmt":"2013-11-11T15:54:59","slug":"hide-web-template","status":"publish","type":"post","link":"http:\/\/www.stuartroberts.net\/index.php\/2013\/10\/19\/hide-web-template\/","title":{"rendered":"Hide Web Template"},"content":{"rendered":"<p>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:<\/p>\n<pre lang=\"PowerShell\">\r\nfunction Remove-SPWebTemplate {\r\n\t[CmdletBinding()]\r\n\tparam(\r\n\t\t[parameter(Position=1,Mandatory=$true)][Microsoft.SharePoint.SPWeb]$web\r\n\t)\r\n\tprocess {\r\n\t\t$templateList = New-Object \"System.Collections.ObjectModel.Collection``1[[Microsoft.SharePoint.SPWebTemplate, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]]\"\r\n\t\t\r\n\t\t$availableWebTemplates = $web.GetAvailableWebTemplates(1033);\r\n\t\t$availableWebTemplates | Where{ $_.ID -ne 53 } | ForEach-Object {\r\n\t\t     $templateList.add($_)\r\n\t\t}\r\n\t\t\r\n\t\tif ($templateList.Count -gt 0) {\r\n\t\t\tWrite-Host (\"Removing Blank Internet web template with from web '\", $_.Title, \"' at \", $_.Url -join \"\") -NoNewline\r\n\t\t\t$web.SetAvailableWebTemplates($templateList, 1033);\r\n\t\t\t$web.Update()\r\n\t\t\tWrite-Host \" - Done.\" -ForegroundColor Green\r\n\t\t}\r\n\t\telse {\r\n\t\t\tWrite-Host (\"No web templates found for web \", $_.Url -join \"\") -ForegroundColor Red\r\n\t\t}\r\n\t}\r\n}\r\n\r\nGet-SPWebApplication | ForEach-Object {\r\n\t$_.Sites | Where { $_.ServerRelativeUrl -ne '\/sites\/example' } | ForEach-Object {\r\n\t\t$_.AllWebs | ForEach-Object {\r\n\t\t\tRemove-SPWebTemplate $_\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p><!--more--><br \/>\nWithin the <em>Remove-SPWebTemplate<\/em> method a list of all currently enabled web templates is added to the <em>templateList<\/em> variable by calling the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.spweb.getavailablewebtemplates.aspx\" title=\"SPWeb.GetAvailableWebTemplates method\" target=\"_blank\">GetAvailableWebTemplates<\/a> method for the web object and adding all templates that don&#8217;t match the one we want to hide.  In this example, that&#8217;s the template with the ID 53 &#8211; Blank Internet.<\/p>\n<p>This collection is then passed into the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/sharepoint\/ms435526.aspx\" title=\"SPWeb.SetAvailableWebTemplates method\" target=\"_blank\">SetAvailableWebTemplates<\/a> method to define the visible template for new sites created within the web.<\/p>\n<p>In this example, the webs have been restricted to those in the site collection &#8216;\/sites\/example&#8217;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8220;System.Collections.ObjectModel.Collection&#8220;1[[Microsoft.SharePoint.SPWebTemplate, Microsoft.SharePoint, &hellip; <a href=\"http:\/\/www.stuartroberts.net\/index.php\/2013\/10\/19\/hide-web-template\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":[]},"categories":[3],"tags":[41,81],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/plx2I-pi","_links":{"self":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1568"}],"collection":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/comments?post=1568"}],"version-history":[{"count":8,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1568\/revisions"}],"predecessor-version":[{"id":1573,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1568\/revisions\/1573"}],"wp:attachment":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/media?parent=1568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/categories?post=1568"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/tags?post=1568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}