0

We need to deploy a new library template to all the libraries in our site collection for legal purposes. I need to estimate the amount of time and staff to do this. How do I get a simple count of all libraries in a site collection, and possibly in each site as well? Then I can multiple the per-library time by the number of libraries for an accurate estimate.

The discussions online seem to focus on counts for documents within a library, which is much less important for this deployment. (We'll use Spreadsheet view to associate all docs at once with the new template, so that is a standard time to put in the estimate.)

I don't have access to our Central Admin, so have to explain to our IT person exactly what count/extract I'm asking for. Thanks!

1

You could run the below powershell command :

#Load powershell snapin
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
#Get site collection details
$s = Get-SPSite http://yoursitecollectionurl
#Get all web sites in the site collections
$wc = $s.AllWebs
$count=0
foreach($w in $wc)
{
#loopthrouh the lists and libraries in the site
foreach($l in $w.Lists)
  {
        #Check for only document libraries
        if($l.BaseTemplate -eq "DocumentLibrary")
        {
            $count++
        }
    }
}
Write-Host $count
0

i am just revising the Unnie's script, His script give all libraries including the systems as well.

So, I just exclude those from the Count, also give you the title of the document library.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
#Get site collection details
$s = Get-SPSite https://dev13team.sp.ford.com/sites/TracyFunctest
#Get all web sites in the site collections
$wc = $s.AllWebs
$count=0

$systemlibs =@("Converted Forms", "Customized Reports","Form Templates",  
                              "Images", "List Template Gallery", "Master Page Gallery", "Pages",  
                               "Reporting Templates", "Site Assets", "Site Collection Documents", 
                               "Site Collection Images", "Site Pages", "Solution Gallery",  
                               "Style Library", "Theme Gallery", "Web Part Gallery", "wfpub")

foreach($w in $wc)
{
#loopthrouh the lists and libraries in the site
foreach($l in $w.Lists)
  {
        #Check for only document libraries
        if($l.BaseTemplate -eq "DocumentLibrary")
        {
         if ($systemlibs -contains $l) 
                    { continue} 
                    else{            
$count++
Write-Host $l.title}
        }
    }
}
Write-Host $count
0

I once wrote a jquery script to iterate all subsites and list all its libraries + size. Maybe it's useful to you. Desn't give you the count just lists them

HTML

  <style>
  .site{
    border:1px solid #888;
    margin:10px;
    padding:10px;
    display:block;
}
</style>
<div id="content"></div>

.js

    $(function (){

    var lists = _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists?$select=ContentTypes,Title&$expand=ContentTypes";    
    var webInfos = _spPageContextInfo.webAbsoluteUrl+"/_api/web/webInfos";  

    GetData(webInfos)
    .success(SiteHandler.bind(["content", "Root", _spPageContextInfo.webAbsoluteUrl]))
    .fail(function(){console.log("error parsing data from url: "+lists );});



    function SiteHandler(data, siteInfo)
    {
        var siteInfo = this;

        var parent = cleanId(siteInfo[0]);
        var id = cleanId(siteInfo[0] + siteInfo[1]);


        $("#"+parent).append("<div class='site' id='"+id+"'><h3>"+siteInfo[1]+"</h3></div>");   

        var url = siteInfo[2] +"/_api/web/lists?$select=ContentTypes,Title&$expand=ContentTypes";

        GetData(url)
        .success(ListHandler.bind(siteInfo))
        .fail(function(){console.log("error parsing data from url: "+url );});

        try
        {
            for(i = 0; i < data.d.results.length; i++)
            {               
                var subsite = data.d.results[i].Title;
                var url = data.d.results[i].ServerRelativeUrl+"/_api/web/webInfos";

                var root = id;

                var subsiteInfo = [root, subsite, data.d.results[i].ServerRelativeUrl]
                GetData(url)
                .success(SiteHandler.bind(subsiteInfo))
                .fail(function(){console.log("error parsing data from url: "+url );});          
            }
        } catch(e){ console.log(e);}

    }


    function ListHandler(data, siteInfo)
    {   

        var siteInfo = this;
        for(i = 0; i < data.d.results.length; i++)
        {           
            var cts = data.d.results[i].ContentTypes;
            for(j = 0; j < cts.results.length; j++)
            {
                if(cts.results[j].Name == "Document")
                {
                    try
                    {                   
                        var lib = data.d.results[i].Title.split("%20").join(" ");
                        var info = [siteInfo, lib];
                        var url = siteInfo[2]+"/_api/web/lists/GetByTitle('"+lib+"')/items?$select=*&$expand=File";                                         

                        GetData(url)
                        .success(AddList.bind(info))
                        .fail(function(){console.log("error parsing data from url: "+url);});


                    } catch(e){console.log(e);}
                    break;
                }               
            }
        }
    }


    function AddList(data,info)
    {


        var info = this;

        var parentId = cleanId(info[0][0]) + cleanId(info[0][1]);
        var id = parentId + cleanId(info[0][1]) + cleanId(info[1]);     


        $("#"+parentId ).append("<div class='libBlock' id='"+id+"'>"+info[1]+" </div>");

        var size = 0;
        for(k = 0; k < data.d.results.length; k++)
        {
            var s = parseInt(data.d.results[k].File.Length);
            if(!isNaN(s)) size += s;
        }

        var px = size / 200000;
        if(px > 30) px = 30;
        if (px < 9) px = 9;


        $("#"+id).append(size.formatInt(0));    
        $("#"+id).css("font-size", px+"px");    
    }   


});




function cleanId(s)
{
    s = s.split(" ").join("");
    s = s.split("&").join("");
    s = s.split('"').join("");

    return s;


}


Number.prototype.formatInt = function(c, d, t)
{
    var n = this, 
    c = isNaN(c = Math.abs(c)) ? 2 : c, 
    d = d == undefined ? "." : d, 
    t = t == undefined ? "," : t, 
    s = n < 0 ? "-" : "", 
    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", 
    j = (j = i.length) > 3 ? j % 3 : 0;
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}       


function GetData(url)
{       
    return $.ajax({
        url:url,
        method:"GET",
        headers: { "Accept": "application/json; odata=verbose" },
    });
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.