Press enter to see results or esc to cancel.

Generate list item count report in SharePoint using PowerShell

This post has less to do with how to obtain this information from SharePoint and is more about making use of the native capabilities of PowerShell coupled with the SharePoint specific PowerShell cmdlets to make the resulting PowerShell code more configurable and pleasing to the eye.

Pipelines are very effective in enumerating, sorting and filtering collections and hence serve as the perfect candidate for enumerating the hierarchical structure of the SharePoint object model. Following is an excerpt from the final code that basically enumerates all possible site collections and web sites within a particular web application.

Get-SPWebApplication $webAppUrl -ErrorAction silentlycontinue  | Get-SPSite -Limit All -ErrorAction silentlycontinue | Get-SPWeb -Limit All -ErrorAction silentlycontinue 

Finally, you can use the Export-CSV native PowerShell command to write all the extracted tabular data to a csv file. Following is the final code used to display information regarding all lists exceeding a particular item count.

if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
    Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

$runningDir = resolve-Path .\
$outputPath = join-path -path $runningDir -childpath "output$(get-date -f yyyy-MM-dd-hh-mm-ss).csv"
$minCount = 0;
$webAppUrl = 'http://dxbegww70dv';

Get-SPWebApplication $webAppUrl -ErrorAction silentlycontinue  | Get-SPSite -Limit All -ErrorAction silentlycontinue | Get-SPWeb -Limit All -ErrorAction silentlycontinue | Foreach { 
    $web = $_;
    $lists = $web.lists;
    $lists | ? { $_.ItemCount -ge $minCount } | Select @{Name="Site Url";Expression={$_.ParentWeb.Site.Url}}, @{Name="Web Url";Expression={$_.ParentWeb.Url}}, @{Name="List Name";Expression={$_.Title}}, @{Name="Item Count";Expression={$_.ItemCount}} | Export-CSV $outputPath -Append -NoTypeInformation -Force;
} 

Download GetCountAll.

Comments

Leave a Comment