Report on every library in a SharePoint Farm

79

Report on every library in a SharePoint Farm

It is very useful to be able to examine attributes from every library in a SharePoint farm. Here’s how to generate a report of useful library summary information, such as what level of versioning is enabled, which libraries are configured for QuickLinks and which have Content Types enabled, and how many documents are within each library. I use pipe-separated fields, in case commas are encountered in library fields, such as titles.

Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
$mylogfile="L:PowerShellCOREreportingLibSettings.csv"

$envrun="Prod"			# selects environment to run in
if ($envrun -eq "Dev")
{
$siteUrl = "http ://SharePoint Dev/"
}
elseif ($envrun -eq "Prod")

{
$siteUrl = "http ://SharePoint/"
}
else
{
Write-Host "ENVIRONMENT SETTING NOT VALID: script terminating..."
$siteUrl =  $null;
return;
}

Write-Host "script starting" 

$myheader = "STARTING: $(get-date)"
$Sep="|"
add-content $mylogfile "Site$($sep)Web$($sep)Library$($sep)FileCount$($sep)CTEnabled$($sep)VerMajor$($sep)VerMinor$($sep)QuickLaunch$($sep)MajVerLimit$($sep)MinorVerLimit$($sep)UniquePerms"

$WA=Get-spWebApplication $siteUrl;
foreach ($site in $wa.sites)
{
  write-host $site.Url
foreach ($web in $site.allwebs)
{

  if ($true) #useful placeholder for filtering. 
  {
   Write-Host -foregroundcolor darkgreen "$($site.id) - $($site.Url) - $($site.contentdatabase.id) - $($site.contentdatabase.name)"   
 

   for ($i=0;$i -lt $web.Lists.Count;$i++)
   { 
   $JPLib=$web.Lists[$i];
   $A_Lib_Count++;
   $SkipLib=$true; #true
   
   if ( ($JPlib.BaseType -ne "DocumentLibrary") -or ($JPlib.hidden) )
    {
      # forget the rest and return to top
      Write-Host -foregroundcolor green "fast test skipping Library: $($JPlib)";   
	}
    elseif ($JPLib.Title -Match "SitesAssets|Photo|Image|CustomizedsReports|Templates|Pages|Picture|cache|style|Slide")
    {
      # forget the rest and return to top
      Write-Host -foregroundcolor red "fast test skipping Library because it mentions $Matches: $($JPlib)";   
	}
	elseif ($JPLib.BaseTemplate -ne "DocumentLibrary")   #alternatively, only skip if -eq XMLForm
    {
      # forget the rest and return to top
      Write-Host -foregroundcolor red "fast skipping Library because it is not of base DocumentLibrary, it is BaseType:$($JPlib.basetemplate): $($JPlib.title)";   
	}
	elseif (($JPLib.ThumbnailsEnabled) -or ($JPLib.DefaultView -eq "AllSlides"))
    {
      # forget any library with thumbnails, these are not normal doclibs, and return to top
      Write-Host -foregroundcolor red "fast test skipping Library because it has Thumbnails/Slides $($JPlib)";   
	}
    else
    {  $SkipLib=$false;	}
     
	if (!$SkipLib)
	{
	  #write-Host -foregroundcolor green "Processing Library: $($JPlib)";   

	  $LineOut = "$($site.url)$($sep)$($web.title)$($sep)$($JPLib.title)$($sep)$($JPLib.items.count)$($sep)$($JPLib.ContentTypesEnabled)$($sep)$($JPLib.get_EnableVersioning())$($sep)$($JPlib.get_EnableMinorVersions())$($sep)$($JPLib.OnQuickLaunch)$($sep)$($JPLib.MajorVersionLimit)$($sep)$($JPLib.MajorWithMinorVersionsLimit)$($sep)$($JPLib.HasUniqueRoleAssignments)"
	  Write-Host $lineOut
	add-content $mylogfile $LineOut
	}
	
	}
   
} #foreach site
} #if $true/Siteurl is not null, if environment setup is valid
} #foreach letter
###########################

Start Your SharePoint Online Project in a Click

Our technology and wide delivery footprint have created billions of dollars in value for clients globally and are widely recognized by industry professionals and analysts.

Share this entry

2 Responses

  1. Very interesting scripts. I think I may be able to use them – I’m not big on scripts anymore, let’s just say been there, done that, but. – anyhow. I have a problem with content type default template corruption that appears to require that I turn off ReadOnly for various content types throughout a site collection. I’m wondering if your scripts with ReadOnly would work, with revisions.

    What happened was that I was creating some custom content types to use in Document Sets and for some unknown reason the default Document content type lost its template and all the content types followed along and lost their templates, resulting in the Upload File dialog rather than as a new Blank or Customized Word document. (It also screwed up the templates for Audio, VIdeo, Link to a Document, but those are more easily fixed.) When I, perhaps foolishly, tried to restore the Document content type template, copying from another site collection where it worked, I got this gigantic error that various content types, custom and default as well as System Page Layout and other hidden types were read only or in the case of the hidden stuff, sealed.

    This is quickly becoming a disaster and I really don’t want to go to a few hundred locations to change these content type to ReadOnly=false using the BUI, especially since I suspect that after I’ve gone through all the Content Types and restored their templates, the whole thing will happen again.

    So, would your scripts, modified of course, work for this problem? Any suggestions would be welcome.

    Thanks,

    Barry Cohen
    CTO Edison Group, Inc.

    1. You can definitely easily and quickly in a script iterate through the site collections (get-spsite -limit all) to then grab any content type(s) and flip the readonly boolean value. I often use a CSH (Content Type Syndication Hub) and all its published Content Types appear in the consuming site collections as Readonly, and to customize I often have to flip that boolean, such as within a library.

      Joel

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents

Categories

Categories