PowerShell Script To Get Document Libraries Inventory For Site Collection And Web Application

Objective

This purpose of this article is to mention the PowerShell script details which will help us list out libraries present at site collection level and at web application level

This script offers

  • To read a set of libraries (Document Libraries/Custom List/ Predefined lists) present at site collection level, when attribute is passed as SiteCollection.

  • To read a set of libraries (Document Libraries/Custom List/ Predefined lists) present at each site collection level in a web application, when attribute passed as WebApplication.
Business Case

S. No.Business Case
1For several reasons (Some application troubleshooting, Migration, Testing etc.) SharePoint Support team requires a details about the list of libraries present at each site collection level or at particular site collection level. This script will allow administrator to do this job just running it.

Targeted Audience
  • SharePoint Application Developers
  • SharePoint Administrator
  • SharePoint Architect
Technical Details
  1. Execution

    Prerequisite:

    Login to SharePoint Server as Farm Administrator and copy the required files as per your required location.

    Run:

    • Run the PowerShell Script as “Run as Administrator“.
    • Browse the folder path where you have kept this PowerShell script file and execute a command.
PowerShell Script
  1. function Get-SPSiteInventory {  
  2. Param(  
  3. [string]$Url,  
  4. [switch]$SiteCollection,  
  5. [switch]$WebApplication  
  6. )  
  7. Start-SPAssignment -Global  
  8.     if ($SiteCollection) {  
  9.         $site = Get-SPSite $Url  
  10.         $allWebs = $site.allwebs  
  11.         foreach ($spweb in $allWebs) {  
  12.             " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "  
  13.             $spweb.Url  
  14.             $spweb.Lists | select Title, BaseType  
  15.             $spweb.dispose()  
  16.         }  
  17.         $site.dispose()  
  18.     }   
  19.     elseif ($WebApplication) {  
  20.         $wa = Get-SPWebApplication $Url  
  21.         $allSites = $wa | Get-SPSite -Limit all  
  22.         foreach ($spsite in $allSites) {  
  23.             $allWebs = $spsite.allwebs  
  24.             foreach ($spweb in $allWebs) {  
  25.             " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "  
  26.             $spweb.Url  
  27.             $spweb.Lists | select Title, BaseType  
  28.             $spweb.dispose()  
  29.             }  
  30.         }  
  31.     }  
  32. Stop-SPAssignment -Global  
  33. }  
  34.  
  35. # For Web Application level  
  36. Get-SPSiteInventory -Url http://mywebapplicationURL/ -WebApplication   
  37.  
  38. #For Site collection Level  
  39. Get-SPSiteInventory -Url http://mywebapplicationURL/ -SiteCollection   

Up Next
    Ebook Download
    View all
    Learn
    View all