SharePoint Online: Fix Lookup Field using PowerShell

Problem: SharePoint Online lookup column in a list is broken when the parent lookup list is recreated!

Root Cause:

SharePoint Online list lookup columns are connected with its parent lookup list column through the “List” (GUID of the parent list) and “ShowField” attributes. When the parent lookup list is re-created, its GUID is re-generated and the connectivity between parent and child lookup lists is broken and lookup field values become empty!

sharepoint online fix lookup field using powershell

How to Fix Broken Lookup Column in SharePoint Online?

If you come across the above scenario and your lookup column is broken with empty values, you have to re-link the lookup column with its parent list. Use this PowerShell script to fix the lookup columns in the SharePoint Online list.

$SiteURL = ""
$ParentListName = "Projects"
$ChildListName = "ProjectMilestones"
#Field display names - Case sensitive!
$ParentFieldTitle = "Title"
$ChildFieldTitle = "Project"

#Connect to SharePoint Online
Connect-PnPOnline $SiteURL -Credentials (Get-Credential)

#Get Parent List & Child field
$ParentList = Get-PnPList -Identity $ParentListName
$ChildField = Get-PnPField -List $ChildListName -Identity $ChildFieldTitle

#Get the Field Schema XML
[Xml]$Schema = $ChildField.SchemaXml

#Update Field Schema with New Parent List and Field
$Schema.Field.Attributes["List"].'#text' = "{$($ParentList.Id.Guid)}"
$Schema.field.Attributes["ShowField"].'#text' = $ParentFieldTitle
$ChildField.SchemaXml = $Schema.OuterXml

Also, Remember, We have the parent lookup list saved as a list template with content and created a new list from it, so that the associated row values remain the same! Because, Field value in each row of the lookup field of the child lookup list will be pointing to a row ID in the parent lookup list.

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

5 thoughts on “SharePoint Online: Fix Lookup Field using PowerShell

  • Thank you for the posting. I ran your scripts and “Get information from” is still blank. {$($ParentList.Id.Guid)} got the correct Guid and $Schema.field.Attributes[“ShowField”].’#text’ = $ParentFieldTitle got the field name. Can you please let me know what did I miss?

  • This has been a thorn in my side FOREVER! It works great (If you fix the $ChildListName variable in row 14)!

  • Worked like a charm, thank you very much for this helpful tutorial!


Leave a Reply