Wednesday, May 30, 2012

Find Large SharePoint Lists & Generate Report with PowerShell

This is the PowerShell version of my existing work: Find Large Lists in SharePoint

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

#For Output file generation
$OutputFN = "LargeListsData.csv"
#delete the file, If already exist!
if (Test-Path $OutputFN)
    Remove-Item $OutputFN 
#Write the CSV Headers
Add-Content $OutputFN "List Name , site Collection , Site URL , Item count"

#Get the Web Application URL
$WebAppURL = Read-Host "Enter the Web Application URL:"
$SPwebApp = Get-SPWebApplication $WebAppURL

#Loop through All Site collections, Sites, Lists
      foreach($SPsite in $SPwebApp.Sites) 
        foreach($SPweb in $SPSite.AllWebs) 
          foreach($SPlist in $SPweb.Lists) 
                if($splist.ItemCount -gt 2000) 
                    $content = $SPlist.Title + "," + $SPsite.Rootweb.Title +"," + $SPweb.URL + "," + $SPlist.ItemCount
                    add-content $OutputFN $content
write-host "Large List report generated successfully!"

PowerShell script to find large lists and export to CSV:
Lets do it in one line! Here is the PowerShell one-liner to find Large lists (Lists with more than 2000 items) and export to CSV:
Get-SPWebApplication | Get-SPSite -Limit All | Get-SPWeb -Limit All `
    | Foreach-object { $_.Lists | Select @{N="Url";E={$_.ParentWeb.url+$_.RootFolder.Url} }, Title, ItemCount } `
        | Where {$_.ItemCount -gt 2000} | sort ItemCount -Descending | Export-csv -Path "c:\largeLists.csv" -NoTypeInformation

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:


  1. Hello,

    When I tried to use this script. It askde follwing parmeter from me :
    cmdlet Add-Content at command pipeline position 1
    Supply values for the following parameters:

    Please help me and thanks in advance.


    1. Yogesh,
      I've Seen this error when we call the function without a value to the Name parameter.

      You can try the Operator ">>" to append to text file instead.
      E.g. $SPlist.Title + "," + $SPsite.Rootweb.Title +"," + $SPweb.URL + "," + $SPlist.ItemCount >> LargeListsData.csv


Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...