Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's Office 365 Admin Blog > Posts > Creating and adding items to a SharePoint 2010 list with PowerShell
August 16
Creating and adding items to a SharePoint 2010 list with PowerShell

I was IMing with unsung heroine Lori Gowin today. We were kvetching about how list throttling in SharePoint 2010 is not quite as consistent as we wished it was. She was doing some work for a customer and needed to explain the behavior and take steps to adjust it, if necessary. She was asking if I had any scripts in my bag of tricks to help. Of course I did. Smile I decided to share them with the rest of the class.

First, here’s a script that creates a list using the “Custom" List” template, and adds a column of the type “number” called “Number.” (I know, very creative)

$web = get-spweb http://portal.contoso.com

$web.Lists.Add("LargeList","Big List",$web.ListTemplates["Custom List"])

$list = $web.Lists["LargeList"]

$list.Fields.Add("Number","Number",0)

You can add any columns you’d like, or not add my Number column. Now that the list has been created, let’s add a few thousand items to it. Out of the box, SharePoint doesn’t start throttling lists until there are 5000 items, so you’ll want to create at least that many. This script creates the list items:

for ($i=1; $i -le 5001; $i++)
{
$item = $list.items.add()
$item["Title"] = "Todd is cool " + $i
$item["Number"] = "$i"
$item.update()
}

That will create 5001 items in the list. For whatever reason that script doesn’t seem to work if the text in the Title is not “Todd is cool.” I don’t understand it either. When I ran that on my VM it only took a couple of minutes to run, so it shouldn’t kill your environment.

After the list has more than 5000 items you can experience throttling for yourself. If you’re an administrator SharePoint assumes you know better, and it won’t throttle you until there are 20000 items in the view. That and the 5000 item threshold are set per web application and can be modified in Central Admin or with PowerShell. The user throttling (5000 items) property is MaxItemsPerThrottledOperation while the admin property is MaxItemsPerThrottledOperationOverride and it’s set to 20000 items by default.

Hope that helps, and happy throttling,

tk

Comments

Dispose

When you create a list item you need to dispose it of at the end of creation of each item.
 on 8/17/2011 12:09 AM

No Throttle Needed

People who are new to the blog might think that the whole "Todd is Cool" part needs its own throttle, but that's what's so amazing about this blog and webcast, and, well, Todd.  No Throttle is Needed!  Thanks for the great work, Todd! Love to see it.
 on 8/20/2011 12:16 AM

Re: No Throttle Needed

I'm sure my wife would strenuously disagree with you. :)

tk
Todd O. KlindtNo presence information on 8/22/2011 4:19 PM

I don't get it.

I substituted some random text in for "Todd is cool." and it worked. Am I missing something?
:-)
Mark S.
 on 8/29/2011 9:56 PM

Re: I don't get it.

Hmmm, that's weird. Maybe the behavior changed during one of the service packs. Sounds like a regression to me.

tk
Todd O. KlindtNo presence information on 8/30/2011 7:57 AM

syntax would be

$web = Get-SPWeb -Identity http://sharepoint.com
 on 9/27/2013 4:45 AM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person

Twitter


Want a message when I reply to your comment? Put your Twitter handle here.

Attachments

 

 SysKit