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

I have to recreate the same List in several subsites within a site collection. I saved my List as a template but it will be very time consuming to add the List manually to all of my subsites using the SharePoint GUI. Can anyone point me to a good article or provide a sample of how to do this using PowerShell?

Thanks in advance, Jovi

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

Provided you have added list as a stp file in List template gallery:

    $site = Get-SPSite http://site
    foreach($web in $site.AllWebs) {    
    $listTemplates = $site.GetCustomListTemplates($web)
    $web.Lists.Add("Your name for list", "", $listTemplates["Your List template name"])
    }

Remember, you can't pass the template ID in the Add method but you can easily query on template IDs using PowerShell:'

$web = Get-SPWeb "http://serverUrl"
$template = $web.ListTemplates | Where-Object {$_.Type -eq 10100}
# Now add the list using the retrieved template object...
share|improve this answer
    
Thanks, I was able to create a script that worked. I just have one last question. I searched for the answer but did find anything. The lists that were created did not appear on the quick launch, is there a parameter I can use to do this in powershell. So I don't have to go into the List Setting and manually set the "Display this list on the Quick Launch" to yes. –  Jovi May 9 '13 at 21:50
add comment

Here is an example of creating a list: Create a list with powershell

Then this script will loop through each site in the site collection

$siteURL = "http://sp14fdev01/"
$site = Get-SPSite($siteURL)

foreach($web in $site.AllWebs) {
}

Simply add your list creation code inside the foreach. Note you will want to check to make sure the list doesn't already exist.

share|improve this answer
add comment

hi guys im getting below error when try to save the template

Exception calling "SaveAsTemplate" with "4" argument(s): "The list is too large to save as a template. The size of a template cannot exceed 52428800 bytes."

share|improve this answer
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.