Iterate Through Lists Instead of Document Libraries, Or both

System Info: SharePoint 2010 Enterprise w DEC 2013 CU. 2 WFEs (load balanced), App Server, SSRS Server, Dedicated CA Server (All running Win 2k8 R2).
Background:I have a large (5,000 user) application that is completely customized on top of SP2010. I am the admin, and have been on the team for many years. Previously, we had a development team,
but client has scaled costs back, and now its just me on the technical side. We have a Web app that houses multiple Site Collections, and each site collection has various subsites.
My Problem: We have increased the LVT to 10k items (system has plenty of HP, although we do see performance degradation). Each subsite in the Site Collection holds data specific to an organization
wtihin the Line of Business. There are two lists that frequently approach the 10k mark, and we have mitigation steps in place (essentially, we just create a new SubSite for them once they reach 10k). What I need is a single script that will traverse ALL subsites
and return a count of their lists, perhaps I can work a couple of if statements in there to have specific data written to a SP List (if count is greater than 5000), and other wise everything gets written to the output file.
I am trying to iterate through all lists and return a count of folders + items ... The script below works just fine, but it goes through Document Libraries only (per the baseType eq tag).
I've tried changing baseType from DocumentLibrary to GenericList, but I continually get an error.
I've also removed the where baseType = DocLib clause completely, and this has the desired results (all lists and doclibs are listed), except the 'WebUrl' field in the csv output is blank.
Any thoughts on how I can make a small tweak to this script to get my desired results?
Start-SPAssignment -Global
$OutputFile ="D:\folder\DocCount3.csv"
$results = @()
$webApps = Get-SPWebApplication http://WebAppURL
foreach($webApp in $webApps)
foreach($siteColl in $webApp.Sites)
foreach($web in $siteColl.AllWebs)
$webUrl = $web.url
$docLibs = $web.Lists | Where-Object {$_.baseType -eq "DocumentLibrary"}
$docLibs | Add-Member -MemberType ScriptProperty -Name WebUrl -Value {$webUrl}
$results += ($docLibs | Select-Object -Property WebUrl, Title, ItemCount)
$results | Export-Csv -Path $OutputFile -NoTypeInformation
Stop-SPAssignment –Global

You guys won't believe this ... But, the script actually works as intended if I change the baseType tag to "GenericList"... I had been getting errors (about 14 of them) through PowerShell and
assuming the script didn't process, but after looking at the output CSV, it seems that everything worked properly. I think the 14 errors MAY have been corrupted sites (or something?) as it gives me NullValueNotAllowed when trying to "Add-Member" and points
to $WebUrl as being null.
Next up -- working on getting this script to write specific objects to a SP list!

Similar Messages

  • Querying list items of document libraries returns incorrect values.

    I have several document libraries. I am trying to get only the documents that the a selected user has however it is returning other authors documents. Attached is my code. Any help would be greatly appreciated.
    CamlQuery camlQuery = new CamlQuery();
    string query = "<View Scope='Recursive' /><ViewFields><FieldRef Name='File' /><FieldRef Name='FileLeafRef' /><FieldRef Name='LinkFilename'/><FieldRef Name='LinkFilenameNoMenu' /><FieldRef Name='Modified' /><FieldRef Name='Created' /><FieldRef Name='Author' /></ViewFields>" + "<Where><Eq><FieldRef Name='Author' LookupId='TRUE'/><Value Type='Integer'>" + user.Id + "</Value></Eq><AND><Eq><FieldRef Name='ContentType' /><Value Type='Computed'>File</Value></Eq></And></Where>" +
    "<OrderBy><FieldRef Name='Created' /><FieldRef Name='Modified' /></OrderBy><QueryOptions><RowLimit>" + count + "</RowLimit></QueryOptions></View>";
    camlQuery.ViewXml = query;
    listItems = list.GetItems(camlQuery);
    clientContext.Load(listItems);
    clientContext.ExecuteQuery();

    Hi,                                                             
    The CAML statement below can filter the documents created by a specific user,
     please test it in your environment:
    @"<View Scope='RecursiveAll'>
    <Query>
    <Where>
    <Eq>
    <FieldRef Name='Author' />
    <Value Type='User'>Display Name</Value>
    </Eq>
    </Where>
    </Query>
    <ViewFields>
    <FieldRef Name='FileLeafRef' />
    <FieldRef Name='Author' />
    </ViewFields>
    </View>";
    Best regards
    Patrick Liang
    TechNet Community Support

  • Iterate through list

    i have a list and i want to iterate through the list and get the names of the classes present in that..
    i have the following code
    Iterator it= list.iterator();
    String value;
    while(it.hasNext())
         Object obj= it.next();
         Class cls= obj.getClass();
         value = cls.getName();
    now if i want to check whether a class called test is present in that list how to do that...pls help

    mgv wrote:
    i have a list and i want to iterate through the list and get the names of the classes present in that..
    i have the following code
    Iterator it= list.iterator();
    String value;
    while(it.hasNext())
         Object obj= it.next();
         Class cls= obj.getClass();
         value = cls.getName();
    now if i want to check whether a class called test is present in that list how to do that...pls help
    while(it.hasNext()){
    Object obj = it.next();
    if(obj instanceof test){
        //do something
    }

  • Iterate through List and return (the names) of all the classes

    Hi,
    I've got a List and want to see what kind of classes are in this List.
    List list = getList();
    Iterator it = list.iterator();
    while (it.hasNext()) {
         Object ob = it.next(); // get the next item. Is this the right approach for my problem?
            // Her I want to check the Object what classses it holds,
            // assuming that this is the right approach for my problem
    }Thanks
    Jonny

    Hi,
    that's what I did:
    List list = getList();
    Iterator it = list.iterator();
    while (it.hasNext()) {
         Object ob = it.next(); // get the next item. Is this the right approach for my problem?
             Class cLass = ob.getClass();
             System.out.println("\t" + cLass.getName());
    }This returned java.lang.Object as mentioned.
    Question:
    - Can an Object hold several types of classes? If so, how can I iterate them?
    Mabe this makes things a little clearer:
    Why am asking this? I'm returning a List from a (Hibernate)-query. I can access one Class without problems. Another class that should be returned, I can't access. Thats why I want to know what I'm dealing with.
    Thanks
    Jonny

  • SharePoint Online Iterating through Document Libraries CSOM

    Hi,
    I am trying to iterate though a document library and set each document/items whithin to inherit permissions (at the moment each doc/item is using uniquer permissions).
    I am able to get the specific document library that I am interesting in, however I cannot at the moment iterate though each of the items/documents within it, but here is what I have so far:
    Add-Type -Path "Libraries\Microsoft.SharePoint.Client.dll"
    Add-Type -Path "Libraries\Microsoft.SharePoint.Client.Runtime.dll"
    Add-Type -Path "Libraries\Microsoft.SharePoint.Linq.dll"
    Add-Type -Path "Libraries\Microsoft.SharePoint.dll"
    $webUrl = "https://test.sharepoint.com/sites/testsite"
    $username = "####"
    $password = "####"
    $securePass = ConvertTo-SecureString $password -AsPlainText -Force
    $listname = "TestDoc";
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
    $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePass)
    #variables
    $web = $ctx.Web
    $lists = $web.Lists
    $ctx.Load($lists)
    $ctx.Load($web)
    $ctx.ExecuteQuery()
    #print web URL
    write-host `n "Web Url:" `n $web.Url
    foreach ($list in $lists)
    if ($list.Title -eq "TestDoc")
    #print list name if found
    write-host `n "Found the list:" `n $list.Title `n
    #attempting to iterate through items in the document library
    foreach ($item2 in $list.Items)
    #list the items/documents in the document library
    write-host $item2.Title
    It is the foreach loop I am having trouble at the moment as I am not sure how to loop though each of the items/documents in the document library.
    Any suggestions on the approach I should take would be much appreciated.

    Thanks for the heads up, I have re-worked my script which is simpler and now works like a charm:
    Add-Type -Path "Libraries\Microsoft.SharePoint.Client.dll"
    Add-Type -Path "Libraries\Microsoft.SharePoint.Client.Runtime.dll"
    Add-Type -Path "Libraries\Microsoft.SharePoint.Linq.dll"
    Add-Type -Path "Libraries\Microsoft.SharePoint.dll"
    $webUrl = "https://test.sharepoint.com/sites/testsite"
    $username = "####"
    $password = "####"
    $securePass = ConvertTo-SecureString $password -AsPlainText -Force
    $listname = "TestDoc"
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
    $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePass)
    #get the List/DocLib and load it for use
    $listUpdate = $ctx.Web.Lists.GetByTitle($listname)
    $ctx.Load($listUpdate)
    $ctx.ExecuteQuery()
    #CAML Query to get all items inclusing sub-folders
    $spQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
    $spQuery.ViewXml = "<View Scope='RecursiveAll' />";
    $itemki = $listUpdate.GetItems($spQuery)
    $ctx.Load($itemki)
    $ctx.ExecuteQuery()
    #iterating through the items and reseting permission inheritence
    for($j=0; $j -lt $itemki.Count; $j++)
    $itemki[$j].ResetRoleInheritance()
    $ctx.ExecuteQuery()

  • Display select Document Libraries on Page

    Hello
    I want to display on a page all document libraries with read access, shared access and secured. The best way to categorise these, I think, is to associate libraries with content types. So I'll have 3 content types which dictate permissions. (Permissions set
    manually).
    Now that the libraries have content type I need a way to display them on the page. So if its Content Type Read then I see a green icon, clicking on this will navigate to the library. If CT is Shared then I see an amber icon .. etc.
    I've provided a high level idea but maybe there’s some other way to tag the libraries signifying access levels.. even read the permissions directly..
    Any ideas on how to achieve? I don’t have CQWP (publishing is off) at my disposal so maybe front end / back end code ?

    Hi,
    Based on your description, my understanding is that you want to get all the libraries associated with specific content types.
    I recommend to loop through all the libraries in the site programmatically, then use
    SPList.ContentTypes or List.ContentTypes property to get the content type in the library and check if the content type is the one specified.
    More references:
    http://stackoverflow.com/questions/15219968/how-to-get-list-of-all-document-libraries-from-sharepoint-site-programatically
    http://spdailytips.blogspot.com/2012/06/retrieve-all-document-libraries-in.html
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.contenttypes.aspx
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.list.contenttypes(v=office.15).aspx
    You can also use the SPList.CheckPermissions method to check if the permission of current user on the libraries.
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.checkpermissions.aspx
    Thanks,
    Victoria
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Victoria Xia
    TechNet Community Support

  • Search not crawled some document libraries

    Hi All,
    Recently we were reset the index after that we ran the search full crawl.the problem is only one site collection under 10 document libraries was not indexed.
    we have 25 site collection.under problem is one site collection http://abc.com/site15/ in that number of lists and 10 document libraries is there.
    the problem is search was not crawled those 10 document libraries.
    what we did we created new document library, we copied those items in that document library. again we ran full crawl.
    but search was not crawled new document library also.
    Kindly give me suggestion.

    Hi
    REfer this also
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/88745f73-4b13-4cc5-9b3e-73d042782404/some-documents-are-not-getting-crawled-in-search?forum=sharepointsearchlegacy
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/918b8994-2f70-4331-8a96-5b4a835b0e2f/search-not-not-crawling-a-document-library?forum=sharepointgeneralprevious
    Please remember to click 'Mark as Answer' on the answer if it helps you

  • Users are unable to synchronize document libraries with OneDrive for Business

    Hello,
    We are having an issue with our users attempting to synchronize document libraries with OneDrive for Business. When a user tried to synchronize the document library either via the "SYNC" button on the document library page using IE or by
    manually entering the document libraries path into the OneDrive for Business desktop app they receive the following error
    "We can't connect to the specified SharePoint site". The users have the Edit permission to both the site and the document library. I have performed the following actions in attempt to get the synchronization to work.
    1. Tested giving user the owner permission to the site and document library. same result.
    2. Performed a repair on the users Office 2013 installation.
    An interesting point to note is that I myself am able to synchronize the document libraries using both the "SYNC" button on the document library site and by entering the path manually in the desktop app. Difference between my account and the test
    accounts is that I'm a site collection administrator and farm administrator. Can anyone shed some light onto this issue?

    Hi Corey,
    According to your description, my understanding is that the users cannot sync document libraries with OneDrive for Business.
    I recommend to check the Permission Level to see if the Use Client Integration Features permission is selected.
    If not, check this permission in the corresponding permission level which is granted to the users.
    Please also check if the users have the right permission to sync the document library with OneDrive for Business.
    More reference:
    http://nheylen.wordpress.com/2014/05/15/sync-error-we-cant-connect-to-the-specified-sharepoint-site/
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • Display data from multiple document Libraries in List View Webpart

    Hi All,
    I want to display data from multiple document libraries into one list view webpart(custom i have created)
    I went through the following link http://blogs.msdn.com/b/ramg/archive/2009/04/22/implementing-a-simple-cross-site-collection-list-view-webpart.aspx
    but it tells to display only from one document library.
    My motive behind displaying data in the list view webpart is to achieve the functionality of Check In ,Check Out and other OOB features.
    With Regards,
    Jaskaran Singh

    Hi,
    As there is no such OOTB feature, a workaround is to create a visual web part to gather items from libraries and implement functionalities like Check in, Check out files
    in different libraries.
    The links below will provide more details:
    Create Visual Web Parts in SharePoint
    2010
    A demo about displaying list items in visual web part:
    http://www.dotnetcodesg.com/Article/UploadFile/2/217/Web%20Part%20in%20SharePoint%20To%20Show%20All%20List%20and%20List%20Items.aspx
    About the Check In and Check Out:
    How to Check In a document programmatically
    SPFile.CheckIn method
    and SPFile.CheckOut method
    Best regards
    Patrick Liang
    TechNet Community Support

  • Data View Web Part - List of Subsites and Document Libraries under Current Site - Must be able to Package as Site Template in SPDesigner

    Hi Guys,
    On the home page of each sub site I would like to be able to show a list of subsites and Document libraries that are under the current subsite.
    I started investigating a solution using Datasources with SOAP requests sent to the server but it is very difficult to understand how to surface it on the Data View WebPart.
    I have tried with the search results webpart but the problem is that it does not work well when packaged in a Site Template.
    Please advise.
    Thanks and Regards,
    Rhyan

    Ok,
    Here is the problem:
    When creating a mysite from powershell or script, apparently you can ONLY do this from a wfe (or a server running Microsoft SharePoint Foundation Web Application in services on server).
    You CANNOT create mysites from script on your appserver if it is not also a Web Application Server. I confirmed the same is true in my test farm. I guess I was always running most of these scripts on the webserver.
    I searched all over and cannot find this documented anywhere.
    Who do I contact to have Microsoft document this?
    It's Thursday morning, I've been working non stop since Saturday morning so you don't have to :)

  • Iterate through all documents

    Hi,
    We have a container which contains *1 million* documents, each of which has size 5K. Container type is wholedocument. We need to iterate through all document regualrly using container.getAllDocuments(containerTxn, DBXML_LAZY_DOCS | DBXML_NO_INDEX_NODES). For each document, we will perform a xpath query in xml document in memory.
    The problem here is about whether we should use transaction. If transaction is used, getAllDocuments will report "Lock table is out of available lock entries" error when it scan about 9383 ducuments. Here are lock setting:
    envp->set_lk_max_lockers(6000);
    envp->set_lk_max_locks(6000);
    envp->set_lk_max_objects(8000);
    We have 1 million documents, it is impossible to set lock object to 1 million.
    My questions:
    (1) Is this normal? If so, why performing a dbxml query on the container doesn't cause such an error. I believe dbxml query has to iterate all of documents too.
    (2) Is it possible to use a seek position for getAllDocuments? Thus we can commit transaction every iterating 1000 documents, and then continue the iteration from the last seek position.
    (3) if we don't use transaction to call getAllDocuments, what possible problems will happen? Other threads are using transaction to read/update the documents.
    Thanks.
    -Yuan

    Yuan,
    The quickest thing to try is to add the flag DB_READ_COMMITTED to getAllDocuments(). That may reduce the number of locks you need. While you may not be able to set the various lock parameters to 1 million, you should set them much larger than you have now (e.g. 50k - 100k) for this sort of operation.
    Not using transactions at all can lead to inconsistent data mostly related to index consistency with document content. Depending on the nature of your updates it may be safe. You could get stray exceptions but nothing should crash. E.g. if you are only adding/removing documents you are probably safe without transactions; although you might iterate to a document that's been removed so you'll see an exception which would have to be ignored. I'm not 100% certain this will work well but if you can test it in a high-update environment and see no issues that will tell you. The read side will not interfere with the updates.
    As for "seeking" if you look under the covers getAllDocuments() is really just a wrapper for an index lookup on the name index. The XmlIndexLookup API is quite flexible in terms of returning ranges. If you want to look into returning ranges of documents, do this:
    1. look at the code in XmlContainer.cpp in the function "getDocs()". It uses XmlIndexLookup to perform the operation.
    2. look at the XmlIndexLookup API to figure out how to turn the lookup into a range lookup vs looking up ALL items in the index
    Using XmlIndexLookup and tracking the name of your last-used document you can easily ask for all documents "higher" than that one. Further, if you know how your documents are named lexicographically you can give it a maximum as well if you wanted, but given that you can set your XmlQueryContext to be lazy you can simply iterate N times to get the next N documents without paying a penalty retrieving any documents you don't need.
    For the sort of thing you are doing I highly recommend using XmlIndexLookup directly (with or without transactions) to get the flexibility you need. XmlContainer::getAllDocuments() is merely a "convenience" layer on that class.
    Regards,
    George

  • Listing Document Libraries using JavaScript

    Is it possible to use JavaScript to list all document libraries of a site? I would like to create a page that lists all document libraries (where the document library's name meets certain criteria).
    Johan Raeymaeckers

    You can use the Object Model to do this.  MS have authored an article that explains it better than I can here.  It has quite a few interesting other tricks too.
    http://msdn.microsoft.com/en-us/library/hh185009
    Steven Andrews
    SharePoint Business Analyst: LiveNation Entertainment
    Blog: baron72.wordpress.com
    Twitter: Follow @backpackerd00d
    My Wiki Articles:
    CodePlex Corner Series
    Please remember to mark your question as "answered" if this solves (or helps) your problem.

  • HELP:script that iterates through all opened documents and rezise them to match the biggest one.

    Hi,
    I'm making a batch processing action and I really need a script that iterates through all open documents, finds the one with the biggest image size and then iterates one more time to change the rest of the documents to the same image size dimensions. At the end all documents must share identical image size.  I'll really  appreciate if someone can put a quick script for doing this. Thank you !

    I think should do…
    #target photoshop
    if (documents.length > 1) {
         var smallest = 1000000; // Set beyond any size you may be expecting this should do?
         for (var a = 0; a < documents.length; a++) {
              smallest = Math.min(smallest,documents[a].width.as('px'));
         for (var b = 0; b < documents.length; b++) {
              if (documents[b].width.as('px') != smallest) {
                   app.activeDocument = documents[b];
                   var newWidth = new UnitValue(smallest, 'px');
                   documents[b].resizeImage(newWidth,undefined,undefined,ResampleMethod.BICUBICSMOOTHER);
    }else{
         alert("NOT enough docs to resize?");

  • Iterate through a list containing Map items using struts

    Hi friends,
    I have a small problem. I want to iterate through a list of items, using struts.
    The list actually contains map structres for example:
    list(0)
         map(..key..value..)
         map(..key..value..)
         map(..key..value..)
    list(1)
         map(..key..value..)
         map(..key..value..)
         map(..key..value..)
    list(2)
         map(..key..value..)
         map(..key..value..)
         map(..key..value..)can I use <logic:iterate/> for this? if yes how? Because I have used this tag for list containing bean objects not Map.
    Any suggestions are much appreciated.
    Thanks,
    Vishal

    Normally, each object exposed by the iterate tag is an element of the underlying collection you are iterating over. However, if you iterate over a Map, the exposed object is of type Map.Entry that has two properties:
    key - The key under which this item is stored in the underlying Map.
    value - The value that corresponds to this key.
    So, if you wish to iterate over the values of a Hashtable, you would implement code like the following:
    <logic:iterate id="element" name="myhashtable">
    Next element is <bean:write name="element" property="value"/>
    </logic:iterate>
    Best Regards
    Maruthi

  • Iterating through all Document Libraries, Folder and Item -Sharepoint 2010

    Hi
    I want to read all RootFolder,Subfolder along with all "items" from Document Librarie.
    Can anyone please advise on this
    Thanks

    Use caml query with recursiveall which
    will fetch all root folder and subfolder data from a document library.
    for
    your reference.
    http://sharepoint.stackexchange.com/questions/29405/get-items-under-folder-caml
    https://social.msdn.microsoft.com/Forums/office/en-US/6beba66a-adcc-4764-ba0d-ba7870d71457/recursive-caml-query?forum=sharepointdevelopmentprevious
    camlQuery.ViewXml = "<View Scope=\"RecursiveAll\"> " +
    "<Query>" +
    "<Where>" +
    "<Eq>" +
    "<FieldRef Name=\"FileDirRef\" />" +
    "<Value Type=\"Text\">/ecm/Business/Business/Projects/IDECO_P01030000</Value>" +
    "</Eq>" +
    "</Where>" +
    "</Query>" +
    "</View>";
    Regards,
    Rajendra Singh
    If a post answers your question, please click Mark As Answer on that post and Vote as Helpful http://sharepointundefind.wordpress.com/
    Regards, Rajendra Singh If a post answers your question, please click Mark As Answer on that ost and Vote as Helpful http://sharepointundefind.wordpress.com/

Maybe you are looking for