Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Using PowerShell on a SharePoint 2010 site, how can you create a new list from a list template found in the list template gallery?. I want to be able to add several lists at once (just in numerically ascending order). What I have is:

$web = "http://site"
Get-SPWeb $web | ForEach { foreach ($hotdesk in 1,2,3) { $_.Lists.Add("Hot Desk " + $hotdesk, "",
$_.ListTemplates["My List Template"])}}

However, 'My List Template' doesn't work, since it looks like it only uses the built in list templates, not any custom ones that have been created from an existing list or uploaded to the site.

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

you can get the built in list templates using the SPListTemplateType enumeration:

$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::Contacts

if you want to access custom list templates saved as STP files on your site, you have to fetch them from your sites list templates and access them through the list name:

$site = Get-SPSite http://site
$listTemplates = $site.GetCustomListTemplates($web)
$web.Lists.Add("Your new list", "", $listTemplates["ListTemplateName"])

you can also save these list templates using SaveAsTemplate() method on a given SPList object.

share|improve this answer
    
That seems to work, although you only get to see list templates when the account you are running the script as is in the owners group of the site (I ran it as a regular contributor and GetCustomListTemplates returned nothing) –  Sam Mar 10 '11 at 10:42
    
a contributor shouldnt be able to create lists anyhow. That permission are pr default granted to Designers –  Anders Rask Mar 11 '11 at 11:26
    
If a list template is gotten in this way, then we have the reference, but how do we confirm that it is right? How could I write-host and get a confirmation? –  BGM Nov 21 '12 at 18:10
    
i dont understand your question –  Anders Rask Nov 21 '12 at 23:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.