Populating Large Lists using PowerShell

Below is a PowerShell snippet that creates dummy data in a list for large data volume testing.

Add-PSSnapin Microsoft.SharePoint.Powershell

$site = Get-SPSite("http://site-url");
$web = $site.OpenWeb("web-url");
$list = $web.Lists.TryGetList("Large List");

if ($list) {
    
    $colours = "Red", "Green", "Blue";
    $brands = "Toyota", "Mazda", "Volkswagon", "Hyundai", "BMW", "Mercedes", "Suzuki";

    for($i = 0; $i -le 3000; $i++) {
        $item = $list.AddItem();
        $item["Title"] = (Get-Date).Ticks
        $item["Colour"] = $colours[(Get-Random -Maximum $colours.Count)];
        $item["Year"] = Get-Random -Minimum 2000 -Maximum 2017
        $item["Brand"] = $brands[(Get-Random -Maximum $brands.Count)];
        $item.Update();
    }

}

SharePoint List View Threshold

sharepoint-list-view-threshold

Set to 5000 by default, and should not be increased, unless you like slow performing SharePoint sites.

Reducing the list view threshold provides very minimal performance gains, so don’t bother.

Causes

  • Accessing list views that contain too many items
    • Pagination does not help, as the backend query is getting all results, and pagination only breaks up the query results
  • Attempting to perform privileged operations (adding a column, creating an index, adding content types)
  • Custom code that accesses a large list

Mitigation Methods

Continue reading