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

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

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) 


$lookupList=Get-PnPList -Identity $lookupListTitle
$field = Get-PnPField -List $listName -Identity $fieldName 
$schemaXml.Field.Attributes["List"].Value = "{" + $lookupList.Id + "}"
$schemaXml.Field.Attributes["ShowField"].Value = "Title"
Set-PnPField -List $listName -Identity $fieldName -Values @{SchemaXml=$schemaXml.OuterXml}
  • 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. – KmDroid Jan 15 at 10:18
  • If you want to add lookup field to new site, we can use Add-PnPFieldFromXml to achieve it. – LZ_MSFT Jan 16 at 1:19
  • I tried but is not receiving the values from the list, as you can see here: sharepoint.stackexchange.com/questions/255795/… – KmDroid Jan 16 at 14:19
  • You need add lookup list in another site, and then add lookup field to list in this site. – LZ_MSFT Jan 17 at 1:35

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

  • The site that you provided is for insert data in column and not to configure it. – KmDroid Jan 14 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() – Zdeněk Vinduška Jan 15 at 7:35

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.

  • What's the difference between List, ID and SourceID? – KmDroid Jan 14 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.