Sysadminsblog.com Anything for sysadmins!

23Nov/109

Creating a new list in SharePoint 2010 using PowerShell

One of the best new features of SharePoint 2010 is the ability to manage most aspects of SharePoint with PowerShell. A good example of this is creating new lists on sites.

To create a new list you’ll first have to figure out how to tell SharePoint which template to use. Here’s how you can show all template possibilities:

 $SPAssignment = Start-SPAssignment
</p><p>$SPWeb = Get-SPWeb http://localhost -AssignmentCollection $spAssignment
</p><p>$SPWeb.ListTemplates | Select Name, Description

You can use any of the templates returned on that site. To create a list you can use the Add() method:

 $SPTemplate = $SPWeb.ListTemplates["Custom List"]
</p><p>$SPWeb.Lists.Add("List Title","Description",$SPTemplate)

If you want to perform a different action on a list please use

$SPWeb.Lists | Get-Member

to find out what command to use.

To dispose of all the objects that have been called, just run

Stop-SPAssignment $SPAssignment

Be Sociable, Share!

Posted by Mischa Oudhof

Comments (9) Trackbacks (0)
  1. Hi Mischa, thank you for this tip. I noticed an error in the script.

    $PSTemplate = $SPWeb.ListTemplates[“Custom List”] <— Here the name of the variable is PSTemplate

    $SPWeb.Lists.Add("List Title","Description",$SPTemplate) <— Here is SPTemplate

    Cheers
    Riccardo

  2. Hi,

    I’m trying to do the same with the Circulation List but I get this error: “Invalid List Template”

    Any Idea how to resolve this?

    Thx

    Karim

    • When you do the $SPWeb.ListTemplates | Select Name, Description command, is it listed? If not you might be trying to add a list that is not supported in that web. You could try to enable the Circulation List feature (ID: 50ba-4052-ab48-37d8029b3f47), or just all Workgroup features.

  3. Hi , Nice article. Can I use PowerShell to create ListDefinition ?

  4. I can’t get this to work for me in my production SharePoint 2010 environment (works fine in my development environment). I am getting an “Cannot index into a null array.” Any help would would be much appreciated.

    • This error indicates that one of the objects that should be retrieved has not been retrieved properly. Possible explanations can be:
      – You have no permissions on the SPWeb that you’re trying to to retrieve
      – There is no SPWeb at the URL you’ve input
      – You have no permissions to create lists in this web
      – There is no template with the name that you’ve input

      Exactly at what line are you getting this error?

  5. Thanks for the script insight. Worked perfectly!


Leave a comment

No trackbacks yet.