Add additional lookup field by Powershell

06/05/2015 11:40

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$web = get-spweb "https://yoursitecollection"


#in this $list, we already have main lookup field to $targetList
#we want to create additional lookup to show more information from $targetList
$list = $web.Lists.TryGetList("My List");
$existingLookupInternalName = "existingMainLookupInternalName"

#so, set additional lookup internal name, display name and targeting
$targetList = $web.Lists.TryGetList("Source list for lookup");
$targetFieldInternalName = "existingFieldInTargetListInternalName";
$addLookupInternalName = "yourFieldInternalName";
$addLookupDisplayName = "Your Field display name";

#Get lookup what already exist
$lookupField = $list.Fields ' where {$_.InternalName -eq $existingLookupInternalName}
$lookupField

#Add Additional lookup
$addLookupResult = $list.Fields.AddDependentLookup($addLookupInternalName, $lookupField.ID)
$addLookupResult
$addLookupField = $list.Fields.GetFieldByInternalName($addLookupResult);
$addLookupField.Title = $addLookupDisplayName
$addLookupField.LookupField = $targetList.Fields.GetFieldByInternalName($targetFieldInternalName).InternalName;
$addLookupField.Update();

$list.Update();