Total number of list items in a SharePoint Web Application

Ever wondered, how many list items you have in a Web Application?

You can use this Windows PowerShell script to know the total number of list items in a SharePoint Web Application. You can tweak the recursion to get list item details for subsite o for site collection level...

 

Below is the sample script.

 

if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
 {Add-PSSnapin Microsoft.SharePoint.Powershell}
 
$SPWebApp = Get-SPWebApplication("https://intranet.contoso.com")
 
$i=0
foreach ($SPSite in $SPWebApp.Sites)
{
    Write-Host "Going thru Site Collection" $SPSite.Title
    foreach ($SPWeb in $SPSite.AllWebs)
    {
        Write-Host "Going thru Web" $SPWeb.Title
        foreach ($SPList in $SPWeb.Lists)
        {
        Write-Host "Going thru List" $SPList.Title "which has" $SPList.ItemCount "item(s)"
        foreach ($SPListItem in $SPList.Items)
        {
            Write-Host "Going thru Item" $SPListItem.Name
            $i=$i+1
            }
        }
        $SPWeb.dispose()
    }
    $SPSite.dispose()
}
Write-Host "Total item count" $i