Here is the PowerShell script to loop through all the site collections and sites to list out the number of items in a list /library. Output is saved as a csv file.
Save the below script as .ps1 before executing. While running the script enter the URL of the web application and the location to save the output file when requested in the powershell prompt.
This script may not work in all environments or may not be accurate.
#Url of the web application
Write-host “Enter the web application URL:”
$url = Read-Host#Output file location
Write-host “Enter the location to save the output file:(C:\Temp\Filename.csv)”
$OutputFile = Read-Host#Variable for results
$result = @()#Get the web application reference
$webApplication = Get-SPWebApplication $url
foreach($webApp in $webApplication)
{
#loop through all the site collections
foreach($siteCollection in $webApp.Sites)
{
#loop throgh all the sites
foreach($web in $siteCollection.AllWebs)
{
$webUrl = $web.url
$lib = $web.Lists | Where-Object {1}
$lib | Add-Member -MemberType ScriptProperty -Name WebUrl -Value {$webUrl}
$results += ($lib | Select-Object -Property WebUrl, Title, ItemCount)
}
}
}$result | Export-Csv -Path $OutputFile