Thursday 15 February 2018

Get all lists in a SharePoint Web Application using Powershell

Add-PSSnapin Microsoft.SharePoint.PowerShell
  
$SPWebApp = Get-SPWebApplication "http://MySharePointWeb:81/" -ErrorAction SilentlyContinue
# get all the site collections
$SiteCollections = $SPwebApp.Sites
$SiteCollections | ForEach-Object {
# get the all sub sites of site collection
$SubSites = $_.AllWebs
$SubSites | ForEach-Object {
$Site = $_
# get all lists from site
$lists = $Site.Lists | Where-Object { $_.BaseType -eq 'GenericList' }
$lists | ForEach-Object {                
    New-Object -TypeName PSObject -Property @{
              ListName = $_.Title
              SiteName = $Site.Title
              SiteUrl = $Site.Url
}}}}| Export-CSV "C:\\All-Lists.csv" -NoTypeInformation -Encoding UTF8



Get all Document Libraries in a SharePoint web application


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
$SPWebApp = Get-SPWebApplication "http://MySharePointWeb:81/"
# get all the site collections 
$SiteCollections = $SPwebApp.Sites
$SiteCollections | ForEach-Object {
# get the all sub sites of site collection
$SubSites = $_.AllWebs
$SubSites | ForEach-Object {
$Site = $_
 # get all document Libraries from site
$lists = $Site.Lists | Where-Object { $_.BaseType -eq 'DocumentLibrary' }
$lists | ForEach-Object {                                    
    New-Object -TypeName PSObject -Property @{
              LibraryName = $_.Title
              SiteName = $Site.Title
              SiteUrl = $Site.Url
}}}}| Export-CSV "C:\\All-Libraries.csv" -NoTypeInformation -Encoding UTF8

No comments:

Post a Comment