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 |
1 | For 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
- 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
- function Get-SPSiteInventory {
- Param(
- [string]$Url,
- [switch]$SiteCollection,
- [switch]$WebApplication
- )
- Start-SPAssignment -Global
- if ($SiteCollection) {
- $site = Get-SPSite $Url
- $allWebs = $site.allwebs
- foreach ($spweb in $allWebs) {
- " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "
- $spweb.Url
- $spweb.Lists | select Title, BaseType
- $spweb.dispose()
- }
- $site.dispose()
- }
- elseif ($WebApplication) {
- $wa = Get-SPWebApplication $Url
- $allSites = $wa | Get-SPSite -Limit all
- foreach ($spsite in $allSites) {
- $allWebs = $spsite.allwebs
- foreach ($spweb in $allWebs) {
- " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "
- $spweb.Url
- $spweb.Lists | select Title, BaseType
- $spweb.dispose()
- }
- }
- }
- Stop-SPAssignment -Global
- }
-
- # For Web Application level
- Get-SPSiteInventory -Url http:
-
- #For Site collection Level
- Get-SPSiteInventory -Url http: