Wednesday, March 7, 2018

Get number of all files on SharePoint farm

How to get number of all files in libraries in SharePoint farm


Add-PSSnapin Microsoft.SharePoint.PowerShell
Start-SPAssignment -Global
$OutputFile = “C:\Temp\DocCount.csv”
$results = @()
$webApps = Get-SPWebApplication
foreach($webApp in $webApps)
{
    foreach($siteColl in $webApp.Sites)
    {
        foreach($web in $siteColl.AllWebs)
        {
            $webUrl = $web.url
            $docLibs = $web.Lists | Where-Object {$_.baseType -eq “DocumentLibrary”}
            $docLibs | Add-Member -MemberType ScriptProperty -Name WebUrl -Value {$webUrl}
            $results += ($docLibs | Select-Object -Property WebUrl, Title, ItemCount)
        }
    }
}
$results | Export-Csv -Path $OutputFile -NoTypeInformation
   
Stop-SPAssignment -Global

No comments:

Post a Comment