3

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

3

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...
  • 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
  • $list.OnQuickLaunch = $True – Bunzab Jan 31 '17 at 23:46
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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