Friday, November 21, 2014

PowerShell Script for retrieving list of libraries from specific Site Collection

---Script to get libraries excluding documentlibrary----

$site = Get-SPSite '<>'
foreach ($web in $site.AllWebs)
{
  foreach ($list in $web.Lists)
   {
   if ( $list.BaseType -ne 'DocumentLibrary')
{
       write-host $list.title
 }
}
}
$web.dispose()

---Script to get libraries which are documentlibrary----

$site = Get-SPSite '<>'
foreach ($web in $site.AllWebs)
{
  foreach ($list in $web.Lists)
  {
  if ( $list.BaseType -eq 'DocumentLibrary')
{
       write-host $list.title
 }
}
}
$web.dispose()


Paste the below code in a file with ps1 as an extension(Ex:getlibrary.ps1) and execute the script in Management Shell as ".\filename.ps1" (Ex: .\getlibrary.ps1)