Friday, April 27, 2012

PowerShell: Total number of documents in SharePoint Site and Sub-Site

Let's say you want to know total number of document's in your SharePoint app including sub-site. Output is an excel file. Change the column in the script if you need additional columns here.

function Get-DocInventory($siteUrl, $outFileNameWithPath) {

$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)

$spWebApp = $rootSite.WebApplication

foreach ($site in $spWebApp.Sites) {

foreach ($web in $site.AllWebs) {

foreach ($list in $web.Lists) {

if ($list.BaseType -ne "DocumentLibrary") {


if ($list.Hidden) {


foreach ($item in $list.Items) {

$data = @{

"Web Address" = $web.Url

"Doc Lib Name" = $list.Title

"File URL" = $item.Url

"File name" = $

"Title" = $item.Title

"Created" = $item["Created"]

"Created By" = $item["Created By"]}

New-Object PSObject -Property $data}}



Write-Host "File written to " $outFileNameWithPath}

function Get-Docs()


$siteUrl = Read-Host "Enter Site URL"

$outFilePath = Read-Host "Enter output file path (without file name)"

$outFileNameWithPath = $outFilePath.ToString() + "\uploadedDocs.csv"

Get-DocInventory $siteUrl $outFileNameWithPath
Export-Csv -NoTypeInformation -Path $outFileNameWithPath

#Set-ExecutionPolicy RemoteSigned

No comments: