Tuesday, June 20, 2017

Count total documents from all document libraries of Site Collection using PowerShell


$site = New-Object Microsoft.Sharepoint.SPSite("https://site collection name or any site");  # Get spsite object
$body = "Site Collection Document Audit for $site`r`n"
foreach ($web in $site.AllWebs)
{
    $url = $web.Url;
    $body = $body + "Web: $url`r`n";
    $lists = $web.GetListsOfType(1);   #Get all document libraries;
    foreach($list in $lists)
    {
       
        $count = $list.Items.Count;
        $title = $list.Title
        $body = $body + "        -  $title :$count items.`r`n"
    }
    $body = $body + "`r`n";
    write-host $body
$web.Dispose();
}
$site.Dispose();