Add Lookup Field to SharePoint List using PowerShell

PowerShell script to add lookup field to SharePoint list:

Scenario: You have a parent list called "Parent Projects" and child list "Project Milestones". The "Parent Project Name" field in child list is being looked up from the parent list's "Project Name" field.
sharepoint powershell add lookup column to list

PowerShell to Add Lookup Field to SharePoint List:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

#configuration parameters
$ParentListName="Parent Projects"
$ChildListName="Project Milestones"

$ParentLookupColumnName="Project Name"
$ChildLookupColumnName="Parent Project Name"

#Get the Parent and Child Lists
$Web = Get-SPWeb $WebURL
$ParentList = $web.Lists[$ParentListName]
$ChildList = $web.Lists[$ChildListName]

#Check if Field exists already
    #sharepoint powershell - create lookup field
    $ChildLookupColumn = $ChildList.Fields.AddLookup($ChildLookupColumnName,$,$False)
    $ChildLookupColumn = $ChildList.Fields[$ChildLookupColumnName]

    #Setup lookup Field property
    $ChildLookupColumn.LookupField = $ParentList.Fields[$ParentLookupColumnName]
    write-host "Lookup field added successfully!" -f green
    write-host "Field Exists already!" -f red
That's all! We've created lookup column using PowerShell in SharePoint list.


  1. how to create sharepoint list view using powershell from content type column

  2. Can I Add Additional Lookup Field?


Please Login and comment to get your questions answered!

Powered by Blogger.