4

I create a column "TitleLookUp" of type LookUp, how can I access the column and configure the information via PNP PowerShell?

2
  • What specifically are you trying to configure? Commented Jan 14, 2019 at 14:43
  • @Mike2500 Get Information from, In this column Commented Jan 14, 2019 at 15:28

3 Answers 3

4

Example, we can configure the lookup list and show field for lookup field using the PowerShell below.

Connect-PnPOnline –Url https://tenant.sharepoint.com/sites/lz –Credentials (Get-Credential) 

$listName="CustomList"
$fieldName="TitleLookUp"
$lookupListTitle="LookupList"

$lookupList=Get-PnPList -Identity $lookupListTitle
$field = Get-PnPField -List $listName -Identity $fieldName 
[xml]$schemaXml=$field.SchemaXml
$schemaXml.OuterXml
$schemaXml.Field.Attributes["List"].Value = "{" + $lookupList.Id + "}"
$schemaXml.Field.Attributes["ShowField"].Value = "Title"
Set-PnPField -List $listName -Identity $fieldName -Values @{SchemaXml=$schemaXml.OuterXml}
4
  • How can I add this column to another site? I already have the column on site A and I want to add on site B. Commented Jan 15, 2019 at 10:18
  • If you want to add lookup field to new site, we can use Add-PnPFieldFromXml to achieve it. Commented Jan 16, 2019 at 1:19
  • I tried but is not receiving the values from the list, as you can see here: sharepoint.stackexchange.com/questions/255795/… Commented Jan 16, 2019 at 14:19
  • You need add lookup list in another site, and then add lookup field to list in this site. Commented Jan 17, 2019 at 1:35
0

Here is documentation for Set-PNPListItem with examples of set LookUp or MultiLookUp values: https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/set-pnplistitem?view=sharepoint-ps

2
  • The site that you provided is for insert data in column and not to configure it. Commented Jan 14, 2019 at 15:52
  • Sorry bad reading from my side :D Here: $list = "listname" $ctx = Get-PnPContext $lkField = Add-PnPField -List $list -DisplayName "fieldname" -InternalName "fieldname" -Type Lookup -AddToDefaultView $lkField = $lookupField.TypedObject $lkField.LookupList = "Lookup List ID" $lkField.LookupField = "Lookup List field name" $lkField.update() $ctx.ExecuteQuery() Commented Jan 15, 2019 at 7:35
0

So you're trying to create a new lookup field via pnp powershell? While add-pnpfield supports adding basic fields, it does not support lookups (yet). See add-pnpfieldfromxml, which allows us to specify an xml schema. It's more work, but it supports the more advanced options. For an example of how to do this for a lookup field, see this answer.

1
  • What's the difference between List, ID and SourceID? Commented Jan 14, 2019 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.