SPListEnumerator


Introduction

This script enumerates through a "large" list or document library and provides information about items in it.

Scenarios

In SharePoint (2007 and 2010) we have a threshold on the number of list items in a container. In SharePoint 2007, the threshold value is 2,000 and in SharePoint 2010, it is 5,000. We often come across customers who have a large number of items in their lists/document libraries and complain of overall site performance. It is possible for customers to create nested folders and have a large number of documents/list items reside in them. But exceeding the threshold value can cause slowness and have a performance impact on the backend SQL content database.

For example, if you have 500,000 documents stored within folders (and nested folders) in a document library, it becomes difficult to identify specific folders that exceed the threshold value. This script traverses through each folder in a given list/document library and will enumerate items at each container level. It writes the output to a .CSV file to make it easier for viewing in Excel and perform further filtering.

This PowerShell script and makes use of the SharePoint Object Model. You will have to provide the name of the list or document library that you want to traverse. The
output is written to an out.CSV file that can be opened in Excel for further filtering of data. The details written include:


Script

Step 1: Modify the script to suit your environment.

You will have to open the script in an editor like notepad.exe, browse towards the end of the list, and modify the site URL, and specify the name of the list/document library. The script defaults to the Root web. 

PowerShell
Edit|Remove
$site = new-object Microsoft.SharePoint.SPSite("http://SiteCollection_URL"$web = $site.rootweb 
$list = $web.Lists["Document_Lirary_OR_List_Name"

 If you wish to open a subsite within the Root web, you can do so by modifying the code as shown below. 

PowerShell
Edit|Remove
$site = new-object Microsoft.SharePoint.SPSite("http://SiteCollection_URL"$web = $site.OpenWeb("Subsite_URL"$list = $web.Lists["Document_Lirary_OR_List_Name"

 Step 2: Run the script from a PowerShell window. The script should finish writing an out.csv file.

Step 3:  Review data. You can use Excel to open the out.csv file.

 

Additional References

Manage large SharePoint lists for better performance

Manage lists and libraries with many items

Designing large lists and maximizing list performance