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.
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.
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.
Once this script gets executed successfully, it will export the Large List Details in a CSV file, as shown below in Step 11,
We can see the exported details below, in Step 12
Code Reference
- Add - PSSnapin "Microsoft.SharePoint.PowerShell"
- Add - PSSnapin "Microsoft.SharePoint.PowerShell"
- function Get - Large - List - Report() {
- Try {
- if (Test - Path $settingsFilePath) {
- Remove - Item $settingsFilePath
- }
- Add - Content $settingsFilePath "WebApp Name,WebApp Url,Site Collection Url,Site Name,Site URL,List Name,List Item Count"
- $spWebApplication = Get - SPWebapplication $webApplicationUrl foreach($spSite in $spWebApplication.sites) {
- foreach($spWeb in $spSite.AllWebs) {
- foreach($spList in $spWeb.Lists) {
- if ($spList.ItemCount - gt 2000) {
- $content = $spWebApplication.Name + "," + $spWebApplication.Url + "," + $spSite.Url + "," + $spWeb.Title + "," + $spWeb.Url + "," + $spList.Title + "," + $spList.ItemCount Add - content $settingsFilePath $content
- }
- }
- $spWeb.dispose()
- }
- $spSite.dispose()
- }
- }
- Catch {
- Write - Host $Error - ForegroundColor Yellow
- }
- }
- Clear - Host $settingsFilePath = "<CSV File Path>"
- $webApplicationUrl = "<Web Application Url>"
- Get - Large - List - Report
That is all for this demo.
Hope you find it helpful.