1

I need to programatically get all SharePoint items in our SharePoint 2010 site's libraries and lists. By programatically I mean using a power shell, SQL query or even a webpart

Libraries can be Asset Libraries, Document Libraries, Form Libraries, Picture Libraries, Report Libraries, Slide Libraries and Wiki Page Libraries.

List can be Links, useful Links and "I need to" Lists.

For each item inside a library or list, I need to find its name, type, created by (user) and modified by (user) fields.

I will need to recursively find all SharePoint sites and for each site, find the information I need.

3

PowerShell:

Get-SPSite "http://yoursite" -Limit All | % {
  $_.AllWebs | % {
    $_.Lists | % {
      $_.Items | % {
        # $_ is now your item
      }
    }
  }
}

Created by field is called Author, and modified by is Editor.
E.g., $_["Author"] and $_["Editor"]

  • A note to the edit ( @nadeem-yosuf ): You don't need to pass in the site url, hence why I left it out – eirikb Mar 6 '15 at 9:41
  • I wasn't aware of this. Now I realize that without having site Url, it will get all site collections in all the web applications. – Nadeem Yousuf Mar 6 '15 at 10:06
  • @eirikb Looking forward getting more fields, how could I get the "Parent site name" and its URL for each item inside the inner loop? – John Casablanca Mar 10 '15 at 3:58
  • @JohnCasablanca You can get the parent through $_.ParentList.ParentWeb, another options is to define variables for each loop, e.g., $_.AllWebs | { $web = $_; $web.Lists | { $list = $_; $list.Items... For an URL to the item you need to build this yourself – eirikb Mar 10 '15 at 6:04
0

In case you want to perform the same operation using C#.

 private void TraversFarm()
    {
        SPFarm farm = SPFarm.Local;
        foreach (SPService curService in farm.Services)
        {
            if (curService is SPWebService)
            {
                SPWebService webService = (SPWebService)curService;
                foreach (SPWebApplication webApp in webService.WebApplications)
                {
                    foreach (SPSite site in webApp.Sites)
                    {
                        using (SPWeb web = site.OpenWeb())
                        {
                            foreach (SPList list in web.Lists)
                            {
                                foreach (SPListItem item in list.Items)
                                { //DO Something here       
                                }
                            }
                        }
                    }
                }
            }
        }
    }

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.