{"id":1575,"date":"2013-11-11T16:03:42","date_gmt":"2013-11-11T16:03:42","guid":{"rendered":"http:\/\/www.stuartroberts.net\/?p=1575"},"modified":"2013-11-11T16:03:42","modified_gmt":"2013-11-11T16:03:42","slug":"show-web-template","status":"publish","type":"post","link":"http:\/\/www.stuartroberts.net\/index.php\/2013\/11\/11\/show-web-template\/","title":{"rendered":"Show Web Template"},"content":{"rendered":"<p>Carrying on from my previous post <a href=\"http:\/\/www.stuartroberts.net\/index.php\/2013\/10\/19\/hide-web-template\/\" title=\"Hide Web Template\" target=\"_blank\">Hide Web Template<\/a>, this post demonstrates how to show a web template in the New Site dialog for a specific web using a PowerShell script:<\/p>\n<pre lang=\"PowerShell\">\r\nfunction Add-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$templates = 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$availableWebTemplates = $web.GetAvailableWebTemplates(1033);\r\n\t\t\r\n\t\t$availableWebTemplates | ForEach-Object {\r\n\t\t\tif ($_.ID -eq 53) {\r\n\t\t\t\tWrite-Host (\"Blank Internet web template is already enabled for web '\", $_.Title, \"' at \", $_.Url -join \"\") -NoNewline\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t$templates.add($_)\r\n\t\t}\r\n\t\t\r\n\t\t$web.AllowAllWebTemplates()\r\n\t\t$allWebTemplates = $web.GetAvailableWebTemplates(1033);\r\n\t\t\r\n\t\t$allWebTemplates | Where{ $_.ID -eq 53 } | ForEach-Object {\r\n\t\t\t$templates.add($_)\r\n\t\t}\r\n\t\t\r\n\t\tWrite-Host (\"Enabling Blank Internet web template for web '\", $_.Title, \"' at \", $_.Url -join \"\") -NoNewline\r\n\t\t$web.SetAvailableWebTemplates($templates, 1033);\r\n\t\t$web.Update()\r\n\t\tWrite-Host \" - Done.\" -ForegroundColor Green\r\n\t}\r\n}\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\tAdd-SPWebTemplate $_\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p><!--more--><\/p>\n<p>The method <em>Add-SPWebTemplate<\/em> is called for each web where we want to show a particular template in the New Site dialog.<\/p>\n<p>First, we get a list of all currently enabled site templates 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 of the passed SPWeb object.  We then check to see if the template we are looking to enable is already configured to be shown in the new Site dialog and where it is the script stops as there&#8217;s nothing else to do.<\/p>\n<p>Assuming the template was not found and therefore is not enabled, we maintain a collection of all currently enabled templates in the variable <em>$templates<\/em><\/p>\n<p>Next, we call the method <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.spweb.allowallwebtemplates.aspx\" title=\"SPWeb.AllowAllWebTemplates method\" target=\"_blank\">AllowAllWebTemplates<\/a> and then call the <em>GetAvailableWebTemplates<\/em> method once more.  All templates will be returned, including those that are not enabled.<\/p>\n<p>This time, when we find the template matching the one we want, Blank Internet in this example, we add it to the <em>$templates<\/em> variable.<\/p>\n<p>Finally, we call the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms435526.Aspx\" title=\"SPWeb.SetAvailableWebTemplates method\" target=\"_blank\">SetAvailableWebTemplates<\/a>, pass it the <em>$templates<\/em> variable, which includes the web template we want to enable, and call <em>Update<\/em> on the web to save the changes.<\/p>\n<p>The webs have been restricted to those in the site collection &#8216;\/sites\/example&#8217; for this example.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Carrying on from my previous post Hide Web Template, this post demonstrates how to show a web template in the New Site dialog for a specific web using a PowerShell script: function Add-SPWebTemplate { [CmdletBinding()] param( [parameter(Position=1,Mandatory=$true)][Microsoft.SharePoint.SPWeb]$web ) process { &hellip; <a href=\"http:\/\/www.stuartroberts.net\/index.php\/2013\/11\/11\/show-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-pp","_links":{"self":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1575"}],"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=1575"}],"version-history":[{"count":3,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1575\/revisions"}],"predecessor-version":[{"id":1597,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1575\/revisions\/1597"}],"wp:attachment":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/media?parent=1575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/categories?post=1575"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/tags?post=1575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}