I am using SharePoint 2013, I need to create a lookup field through PowerShell.
I tried this code but is not working:
$SiteUrl = "http://mySite"
$WebObj = Get-SPWeb -identity $SiteUrl
$myCustomList = $WebObj.Lists["newList"]
$ParentList=$WebObj.Lists.item("listTarget")
$myCustomList.Fields.AddLookup("NewLookupField",$ParentList.id,$false)
$SPChildListLookupField = $myCustomList.Fields[$_.NameField]
$SPChildListLookupField.LookupField = $ParentList.Fields["fieldTarget"]
I want to lookup to a list on a custom field (not the default Title)