SharePoint Migration - Large List Details

This article is the latest in the series of articles on “SharePoint Migration & Planning” Strategies. You can check out the previous articles in this series using the following links,

In this article, we will look for the PowerShell scripts to export “SharePoint Large Lists” Report from SharePoint Farm source. This information will be helpful to track all the lists which contain more than “2000” items in it and are provisioned in a SharePoint Farm.

In Step 1, we will add the PowerShell Snapin to PowerShell Script as usual.

SharePoint Migration - Large List Details 

In Step 2, we define a function and initiate the export CSV file with Column Headers. For this demo I am exporting a few important properties like “WebApp Name, WebApp Url, Site Collection Url, Site Name, Site URL, List Name, List Item Count” but you may query all possible properties as you deemed fit

In Step 3, we execute the “Get-SPWebApplication” cmdlet to query the “Sites” & “Webs” Properties

In Step 4, we loop through the Sites Collection for a specific Web Application

In Step 5, we loop through the Web Collection for a specific Site

In Step 6, we loop through the List Collection for a specific Web address

In Step 7, we will filter all those lists which are having over “2000” items in them

In Step 8, we add the contents of properties for each of the lists to the CSV file

Always remember to dispose of SharePoint Site & Web objects to avoid memory leaks. In Step 9, we will call the “dispose()” method.

SharePoint Migration - Large List Details

In Step 10, we will initialize path variables for export file & web applications. You can further extend this step by adding a little bit more automation flavor to make it more dynamic by reading parameters from the input settings file.

SharePoint Migration - Large List Details

Once this script gets executed successfully, it will export the Large List Details in a CSV file, as shown below in Step 11,

SharePoint Migration - Large List Details

We can see the exported details below, in Step 12

SharePoint Migration - Large List Details
Code Reference

  1. Add - PSSnapin "Microsoft.SharePoint.PowerShell"  
  2. Add - PSSnapin "Microsoft.SharePoint.PowerShell"  
  3. function Get - Large - List - Report() {  
  4.     Try {  
  5.         if (Test - Path $settingsFilePath) {  
  6.             Remove - Item $settingsFilePath  
  7.         }  
  8.         Add - Content $settingsFilePath "WebApp Name,WebApp Url,Site Collection Url,Site Name,Site URL,List Name,List Item Count"  
  9.         $spWebApplication = Get - SPWebapplication $webApplicationUrl foreach($spSite in $spWebApplication.sites) {  
  10.             foreach($spWeb in $spSite.AllWebs) {  
  11.                 foreach($spList in $spWeb.Lists) {  
  12.                     if ($spList.ItemCount - gt 2000) {  
  13.                         $content = $spWebApplication.Name + "," + $spWebApplication.Url + "," + $spSite.Url + "," + $spWeb.Title + "," + $spWeb.Url + "," + $spList.Title + "," + $spList.ItemCount Add - content $settingsFilePath $content  
  14.                     }  
  15.                 }  
  16.                 $spWeb.dispose()  
  17.             }  
  18.             $spSite.dispose()  
  19.         }  
  20.     }  
  21.     Catch {  
  22.         Write - Host $Error - ForegroundColor Yellow  
  23.     }  
  24. }  
  25. Clear - Host $settingsFilePath = "<CSV File Path>"  
  26. $webApplicationUrl = "<Web Application Url>"  
  27. Get - Large - List - Report  
That is all for this demo.

Hope you find it helpful.