-2

I have tried with below script but it is not working,please share the script,if you have any idea.

[Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") 

Start-SPAssignment -Global 

 

$starttime = Get-Date 


$siteurl = Read-Host "Site URL"; 

$site = New-Object Microsoft.SharePoint.SPSite($siteurl)

 

$webs = $site.Allwebs

$systemlibs =@("Converted Forms", "Customized Reports", "Documents", "Form Templates", 

"Images", "List Template Gallery", "Master Page Gallery", "Pages", 

"Reporting Templates", "Site Assets", "Site Collection Documents", 

"Site Collection Images", "Site Pages", "Solution Gallery", 

"Style Library", "Theme Gallery", "Web Part Gallery", "wfpub")

 

Write-Host "Total number of webs that will be traversed: " $webs.count

 

$DocLibsCount = 0 

$DocLibwItems = 0 

$totalitems = 0 

$subfolderitems = 0

$docLibTitle = ""

 

foreach($web in $webs) 

{ 

$listcoll = $web.lists 



foreach($list in $listcoll) 

{ 

if($list -eq $null) 

{ 

Write-Host 

} 

else 

{ 

$base = $list.GetType() 

if($base.name -eq "SPDocumentLibrary") 

{ 

if ($systemlibs -contains $list) 

{ continue} 

else 

{ 

$docLibTitle = $docLibTitle + " | " + $web.url + " : " + $list.Title



$DocLibsCount += 1 

$items = $list.items 



if($items -ne "0") 

{ 

$DocLibwItems += 1 

#Write-Host "Processing ItemCount for DobLib " $DocLibsCount -ForegroundColor Red 

$totalitems += $items.count 



$name = $list.Title 

$folders = $web.GetFolder($name).SubFolders 

for($etr = 0;$etr -lt $folders.count; $etr++) 

{ 

if($folders[$etr].Name -ne "Forms") 

{ 

#Write-Host "Processing SubFolder ItemCount" -ForegroundColor Red 

$tempcount = $folders[$etr].ItemCount 

$subfolderitems += $tempcount 

} 

} 

} 

} 

} 

} 

} 

} 



Write-Host 

Write-Host 

$str1="URL : " + $siteurl    + "`r`n"

Write-Host "URL : " + $siteurl -ForegroundColor Green 

$str1 = $str1 + "Total # of Document Libraries: " + $DocLibsCount + "`r`n"

Write-Host "Total # of Document Libraries: " $DocLibsCount -ForegroundColor Green 

$str1 = $str1 + "Total # of Document Libraries that contain items: " + $DocLibwItems + "`r`n"

Write-Host "Total # of Document Libraries that contain items: " $DocLibwItems -ForegroundColor Green 

$str1 = $str1 + "Total # of items: " + $totalitems + "`r`n"

Write-Host "Total # of items: " $totalitems -ForegroundColor Green 

$str1 = $str1 + "Total # of items in DocLib\Subfolders: " + $subfolderitems + "`r`n"

Write-Host "Total # of items in DocLib\Subfolders: " $subfolderitems -ForegroundColor Green 

$str1 = $str1 + "List of Document Libraries: " + $docLibTitle + "`r`n"

Write-Host "List of Document Libraries: " $docLibTitle -ForegroundColor Green 

$str1=$str1+"`r`n"

$str1 >> sitedetails.txt

$finishtime = Get-Date 

Write-Host 

Write-Host "Script Duration" –ForegroundColor Yellow 

Write-Host "Started: " $starttime –ForegroundColor Yellow 

Write-Host "Finished: " $finishtime –ForegroundColor Yellow

 

Stop-SPAssignment -Global
  • 3
    "but it is not working"... No output? Error messages? Wrong counts? What's not working? – Mike Smith - MCT - MVP Mar 8 '18 at 18:00
  • 1
    Indeed, if you want some help you need to explain the issue better – Tally Mar 9 '18 at 8:55
3

There is a demo to get count of documents in SharePoint site collection.

$NumberOfDoc=0;
$sitecollection=Get-SPSite 'http://sp:5872/'

 $webs= $sitecollection.AllWebs 

      foreach($site in $webs )    
       {    
           foreach($list in $site.Lists)    
          {    
              if($list.BaseTemplate -eq "DocumentLibrary")    
                {    


                      $NumberOfDoc= $NumberOfDoc+$list.ItemCount; #Number item present in document library  

                    Write-Host "Number of Document present in" $list.Title" :" $list.ItemCount;

                  }  

            }  
         } 

 $ScriptFiles="Number of Document in the site colelction"+$NumberOfDoc
Write-Host $ScriptFiles 
 Out-File -FilePath c:\test\test2.csv -InputObject $ScriptFiles -Encoding ASCII -Width 100

And you also can refer to the article to get the detail report of all documents in SharePoint site.

Get detail report of all Documents in SharePoint site using Powershell.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.