As part of my automated deployment post last week, one step of my deployment script called for creating a SharePoint site collection using the “STSADM –o createsite” command with the –sitetemplate option used for a specific site template. If you have never had to create a site collection from a template at the command line you may not know what to put (or know what is available to you) for the –sitetemplate option. To remedy this I created a very simple PowerShell script that opens a site collection and enumerates the usable site templates.

Note: The results listed will be specific to the site collection queried and will most likely be different from the templates in the global site template catalog listed when running STSADM –o enumtemplates. Also note that some results (ex. STS and MPS) have multiple listings with a different # following them. These are the same site template just with different build configurations specified. Using this knowledge we can see that for instance the blank site and team site use the same template just with different components added or activated. You can use this same capability in your own custom site templates if you are making multiple variations of a template.
Code Snippet:
$url = "http://hq.devone.local"
$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
}
$site.Dispose()
Enjoy the script and happy SharePointing adventures.
-Frog Out