Many times we got requirement for client or some to create a custom list and add look up column to it.
As we all know, we can do it thru SharePoint GUI.
But this post will help you to do via Powershell.
So lets get started :)
$SpWeb = Get-SPWeb -Identity "http://SharePoint"
$SpTemplate = $SpWeb.ListTemplates["Name of list"]
$SpListCollection = $SpWeb.Lists
$SpListCollection.Add("listName", "listName", $SpTemplate)
$SpList = $WebObj.Lists["listName"]
$SpList.Fields.AddLookup("ChildLookupField",$ParentList.id,$false)
$SpChildListLookupField = $SpList.Fields["ChildLookupField"]
$SpChildListLookupField.LookupField = $ParentList.Fields["ParentLookupField"]
$SpChildListLookupField.Update()
Happy SharePointing :)
As we all know, we can do it thru SharePoint GUI.
But this post will help you to do via Powershell.
So lets get started :)
Adding a List
$SpWeb = Get-SPWeb -Identity "http://SharePoint"
$SpTemplate = $SpWeb.ListTemplates["Name of list"]
$SpListCollection = $SpWeb.Lists
$SpListCollection.Add("listName", "listName", $SpTemplate)
Adding Lookup Field
$ParentList = $SpWeb.Lists.item("ParentList")$SpList = $WebObj.Lists["listName"]
$SpList.Fields.AddLookup("ChildLookupField",$ParentList.id,$false)
$SpChildListLookupField = $SpList.Fields["ChildLookupField"]
$SpChildListLookupField.LookupField = $ParentList.Fields["ParentLookupField"]
$SpChildListLookupField.Update()
Happy SharePointing :)
No comments:
Post a Comment