Alexander's Blog

Sharing knowledge with the global IT community since November 1, 2004

PowerShell Script to Find Site Template ID

/
/
ad-mania

I often create a new site collection based on Microsoft Office SharePoint Server (MOSS) 2007 Collaboration Portal template for my clients’ intranet site. Just so you know, the Collaboration Portal template is hidden in SharePoint Server 2010. I use a PowerShell script to create the top-level site collection using the site template ID (SPSPORTAL#0) for the Collaboration Portal, as documented in my post Installing Collaboration Portal in SharePoint 2010.

Sometimes you may want to create a site based on your own custom site template that you have previously saved. Of course, if the site is a subsite then you can use the GUI to create the site, unless it’s a hidden template. However, if you want to use a script, and there are several situations where you may want to do that, the following script will come handy to create a new site based on a custom site template. Thanks to SharePoint MVP Alex Pierce for this script.

Step 1

Get the site template ID using the following method.

  1. Enter the following text in Notepad.
    $url = “http://www.contoso.com/”
    $site= new-Object Microsoft.SharePoint.SPSite($url )
    $loc= [System.Int32]::Parse(1033)
    $templates= $site.GetWebTemplates($loc)
    foreach ($child in $templates){ write-host $child.Name “  ” $child.Title}Replace “http://www.contoso.com/” with your site URL.
  2. Save the file with .ps1 extension, e.g. GetSiteID.ps1.
  3. Run the file in PowerShell.
  4. You will see all the sites and their IDs displayed.
  5. Make a note of your custom site’s ID.

Step 2

Use the method documented in my post Installing Collaboration Portal in SharePoint 2010 to create a new site based on your custom site ID.

  • Facebook
  • Twitter
  • Linkedin

Leave a Comment

Your email address will not be published. Required fields are marked *

This div height required for enabling the sticky sidebar