Home Contact

The Frog Pond of Technology

Ripples of Knowledge for SharePoint and Other .Net Technologies

News

 Subscribe to this blog


Upcoming speaker at:

About Me

Name:
Brian T. Jackett
Location:
Columbus, OH
Company:
Sogeti USA

Find me on...

Speaker Rate

Twitter












Archives

Post Categories

Syndication:

Enumerating SharePoint Site Templates for Site Collection with PowerShell

    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.

EnumerateSiteTemplates1

  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


Feedback

# re: Enumerating SharePoint Site Templates for Site Collection with PowerShell

Hi,

I am new to PowerShell Scripts in general and very very new to PowerShell with respect to SharePoint.

After looking your script, I was curious to test in my sharepoint 2010 beta environment.

But, I am getting below pasted Error;

New-Object : Cannot find type [Microsoft.SharePoint.SPSite]: make sure the assembly containing this type is loaded.
At C:\Scripts\EnumeratingSharePointSiteTemplatesForSiteCollectionWithPowerShell.ps1:2 char:18
+ $site= new-Object <<<< Microsoft.SharePoint.SPSite($url )
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

You cannot call a method on a null-valued expression.
At C:\Scripts\EnumeratingSharePointSiteTemplatesForSiteCollectionWithPowerShell.ps1:4 char:34
+ $templates= $site.GetWebTemplates <<<< ($loc)
+ CategoryInfo : InvalidOperation: (GetWebTemplates:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull


You cannot call a method on a null-valued expression.
At C:\Scripts\EnumeratingSharePointSiteTemplatesForSiteCollectionWithPowerShell.ps1:10 char:14
+ $site.Dispose <<<< ()
+ CategoryInfo : InvalidOperation: (Dispose:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Can you please guid me appropriately?


3/6/2010 5:55 AM | Venkatanarasimha KL

# re: Enumerating SharePoint Site Templates for Site Collection with PowerShell

Venkat,

The issue you are seeing is because your PowerShell console has not loaded the appropriate SharePoint DLL (Microsoft.SharePoint.DLL) in order to call the API. There are a few ways to resolve this. One option is if you are running SharePoint 2010 you can just open the SharePoint 2010 Management Shell. This already loads the required references when you open it. Another option (not SharePoint 2010 specific) is to manually load the DLL by using the following command.

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

Let me know if either works for you. Good luck. 3/6/2010 8:08 PM | Brian Jackett

# re: Enumerating SharePoint Site Templates for Site Collection with PowerShell

I am getting below pasted Error;
but thanks for share 7/13/2010 11:11 PM | worldcupjersey

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: