SharePoint 2010 can support up to 30,000,000 items in a list with standard views, site hierarchies and metadata navigation. I’ve never seen a list come close to that, but I did set out to create such a list; mainly to see if it could be done. I didn’t go for 30 million items, I figured 1,000,000 was a good start…
Note: I did this on my VM, not in a client’s environment. 🙂
How did I have the time to create such a large list, you ask? Well, I didn’t. I used PowerShell to automate the whole thing.
PowerShell has become my new favorite tool, and it’s capabilities are truly endless.
The function I created uses standard PowerShell Cmdlets with some parameters to define your list. Here is an example of my script with the necessary parameters. This example would create 50,000 items in a list called MyBigList. Each list item would have a random choice (Red, blue or green) entered into the Category column defined in the list.
.\AddMultipleListItems.ps1 -ListName “MyBigList” -Amount 50000 -Choices “Red;Blue;Green” -ListItem “Added by PowerShell” -WebUrl http://intranet
I don’t know how many people will want to do this, but I can easily see adapting this script for other uses besides demo-ing large list functionality in SP2010.
Here’s the script:
######################################################### ## This script creates list items in a SharePoint list ## ######################################################### ####### Author: Ryan Dennis ############################# ####### Twitter: @SharePointRyan ######################## ####### Blog: www.iccblogs.com/blogs/rdennis ############ ######################################################### ############# Variable Definitions ###################### ## Number of list items to create ## $amount = "1000" ## Start SP Assignment ## $StartSpAssignment = Start-SPAssignment -Global ## Stop SP Assignment ## $StopSpAssignment = Stop-SPAssignment -Global ## Define the categories ## $choices = "Cat1;Cat2;Cat3;Cat4" -split ";" ## The List Name ## $listName = "MyBigList" ## The Web Url ## $webUrl = "http://towncenter/sites/rdennis" ## List Item Title ## $listItem = "Added by PowerShell" ################## The Script ########################### $StartSpAssignment $mylist = (Get-SPWeb -identity $webUrl -AssignmentCollection $StartSpAssignment).Lists[$listName] Write-Host "Creating $amount list items in $listName" -ForegroundColor Green $i = 1 do { $newItem = $mylist.Items.Add() $newItem["Title"] = $listItem $newItem["Category"] = $choices | Get-Random $newItem.Update() $i++ } while ($i -le $amount) Write-Host "Finished!" -ForegroundColor Green $StopSpAssignment
One thought on “Create a Large SharePoint List Using PowerShell”