23Nov/100
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
January 13th, 2011 - 10:18
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
January 20th, 2011 - 09:47
You’re absolutely correct! Thanks for the heads up, will fix this!
September 6th, 2011 - 14:51
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
September 7th, 2011 - 09:10
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.October 19th, 2011 - 16:55
Hi , Nice article. Can I use PowerShell to create ListDefinition ?
October 20th, 2011 - 08:35
For as far as I know, you’ll need to create custom list definitions with Visual Studio. Here’s some more info:
http://msdn.microsoft.com/en-us/library/ff728096.aspx
June 20th, 2012 - 21:08
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.
June 21st, 2012 - 07:54
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?
May 17th, 2013 - 15:45
Thanks for the script insight. Worked perfectly!