Click here to Skip to main content
13,298,451 members (63,329 online)
Click here to Skip to main content
Add your own
alternative version


1 bookmarked
Posted 7 Apr 2014

Get all Lookup Columns in a SharePoint site

, 7 Apr 2014
Rate this:
Please Sign up or sign in to vote.


The following code gets all the lookup columns present in all the list in a site collection. One can modify this to search for lookup columns with a particular name.

Using the code

You need to run the Powershell script in either 'SharePoint 2010 Management Shell' or third party editors like 'Power GUI' etc. Please note that the script should run on the server machine on which the site collection is present.

Also, one has to open the console as 'Administrator', otherwise will get error.

# Add SharePoint Snapin to PowerShell            
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {            
    Add-PSSnapin Microsoft.SharePoint.PowerShell            
function GetAllLookupColumns

        [Parameter(Mandatory=$true, HelpMessage='-URL - Please provide the URL of the site collection.')]

    ) # END PARAMS
    if ($Url)
        #write "Get the url"
        $site = Get-SPSite $Url
        #write "Get the url"
        foreach ($spweb in $site.AllWebs){  
            foreach($list in $spweb.Lists){
                foreach ($field in $list.Fields){ 
                    if($field.Type -eq "Lookup")
                        Write-Host "Match :: WEB - "$spweb.Url" :: Field - "$field" :: List - "$list

    echo "Finished"

To get all the places of lookup columns with a particular name, one can edit this code to have 1 more input parameter of field name and compare that in the IF condition.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Kunal Y
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Volynsky Alex8-Apr-14 5:56
professionalVolynsky Alex8-Apr-14 5:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 7 Apr 2014
Article Copyright 2014 by Kunal Y
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid