SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to itterate all Lists in SharePoint to find out which ones use a custom Lookup field?

I have an application which is currently failing because the custom Lookup field was pointing to a redundant URL which was removed.

share|improve this question
up vote 4 down vote accepted

It is not clear from your question what kind of solution you are looking. My answer is code based and tested on SP 2010 platform.

So here is c# code (link):

    using(SPSite site = new SPSite("http://mysite"))
            SPField fld = site.RootWeb.AvailableFields["[FIELD DISPLAY NAME]"]
            ICollection<SPFieldTemplateUsage> collection = fld.ListsFieldUsedIn();
            foreach (SPFieldTemplateUsage usage in collection)
                SPWeb web = site.AllWebs[usage.WebID];
                SPList list = web.Lists[usage.ListID];
                // Do something here....

or you can use something similar using PowerShell:

$siteUrl = "http://mysite"
$fieldDisplayName = "My Field"   
$site = Get-SPSite $siteUrl
$field = $site.RootWeb.AvailableFields[$fieldDisplayName]
$lists = $field.ListsFieldUsedIn()
$field.ListsFieldUsedIn() | ForEach-Object {
    $w = $site.AllWebs[$_.WebID]
    $l = $w.Lists[$_.ListID]
    Write-Host "Web:" $w.Title "List:" $l.Title "ListUrl:" $l.RootFolder.Url

So I am not iterating lists but instead I am using SPField.ListsFieldUsedIn method to find all field usages.

share|improve this answer
Hi Vedran, seems like a feasible solution. My problem pertains to SP2007, but should still work. I will test this, thank you. – JadedEric Sep 6 '11 at 9:25

I think the line

$l = $web.Lists[$_.ListID]

should be

$l = $w.Lists[$_.ListID]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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