Add Lookup Field to SharePoint List using PowerShell

Requirement: PowerShell script to add lookup field to SharePoint list:

Scenario: You have a parent list called “Parent Projects” and a child list “Project Milestones”. The “Parent Project Name” field in the 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
$WebURL="https://portal.crescent/Projects/"
$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
if(!$childList.Fields.ContainsField($ChildLookupColumnName))
{
    #sharepoint powershell - create lookup field
    $ChildLookupColumn = $ChildList.Fields.AddLookup($ChildLookupColumnName,$ParentList.id,$False)
    $ChildLookupColumn = $ChildList.Fields[$ChildLookupColumnName]

    #Setup lookup Field property
    $ChildLookupColumn.LookupField = $ParentList.Fields[$ParentLookupColumnName]
    #$ChildLookupColumn.AllowMultipleValues=$true
    $ChildLookupColumn.update()
    write-host "Lookup field added successfully!" -f green
}
else
{
    write-host "Field Exists already!" -f red
}

That’s all! We’ve created lookup column using PowerShell in SharePoint list.

Salaudeen Rajack

Information Technology Professional with Two decades of SharePoint Experience.

2 thoughts on “Add Lookup Field to SharePoint List using PowerShell

  • May 12, 2019 at 9:25 AM

    Can I Add Additional Lookup Field?

    Reply
  • May 18, 2018 at 10:15 AM

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

    Reply

Leave a Reply