This script will help you to repair the lookup column in child list which is broken during migration.
Suppose the lookup column looks like this,
Repair Lookup Column In SharePoint Online Using PowerShell
To download SharePoint Online SDK and pass the credential online then please refer to my previous blog, Copy List Items from One Site to Another With Versions using Powershell
Then copy paste the powershell script and run it.
  1. #Load SharePoint CSOM Assemblies
  2. Add-Type -path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'
  3. Add-Type -path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'
  4. $siteUrl="Your Corrupt Column site Url"
  5. $listName="Your Corrupt Column Listname"
  6. $columnName="Your Corrupt Column Name"
  7. $lookupWebURL="Lookup Site Url"
  8. $lookupListName="Lookup List Name"
  9. RepairListLookupColumns $siteUrl $listName $columnName $lookupWebURL $lookupListName
  10. Function RepairListLookupColumns()
  11. {
  12. param
  13. (
  14. [Parameter(Mandatory=$true)] $siteUrl,
  15. [Parameter(Mandatory=$true)] $listName,
  16. [Parameter(Mandatory=$true)] $columnName,
  17. [Parameter(Mandatory=$true)] $lookupWebURL,
  18. [Parameter(Mandatory=$true)] $lookupListName
  19. )
  20. #Passing Credentials
  21. $credPath = 'D:\Arvind\safe\secretfile.txt'
  22. $fileCred = Import-Clixml -path $credpath
  23. $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($fileCred.UserName, $fileCred.Password)
  24. #Get site context
  25. $siteCtx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
  26. $siteCtx.Credentials = $Cred
  27. #Get Loookup context
  28. $lookupCtx = New-Object Microsoft.SharePoint.Client.ClientContext($lookupWebURL)
  29. $lookupCtx.Credentials = $Cred
  30. #Get web, list and column with problems
  31. $siteWeb = $siteCtx.Web
  32. $siteList = $siteWeb.Lists.GetByTitle($listName)
  33. $siteColumn = $siteList.Fields.GetByInternalNameOrTitle($columnName)
  34. $siteCtx.Load($siteWeb)
  35. $siteCtx.Load($siteList)
  36. $siteCtx.Load($siteColumn)
  37. $siteCtx.ExecuteQuery()
  38. #Get web and lookuplist that is source of the lookup column
  39. $lookupWeb = $lookupCtx.Web
  40. $lookupList = $lookupWeb.Lists.GetByTitle($lookupListName)
  41. $lookupCtx.Load($lookupWeb)
  42. $lookupCtx.Load($lookupList)
  43. $lookupCtx.ExecuteQuery()
  44. # Prepare the IDs that are going to be updated
  45. $newLookupListID = $lookupList.ID.ToString()
  46. $newLookupWebID = $lookupWeb.ID.ToString()
  47. # Replaces the XML that defined the Lookup Column
  48. Write-Host $siteColumn.SchemaXml -f DarkYellow
  49. $schema = $siteColumn.SchemaXml
  50. [Xml]$schemaXml = $schema
  51. #$schemaXml.Field.Attributes["WebId"].'#text' = $newLookupWebID
  52. $requiresUpdate = $false
  53. Write-Host "ID's: " $schemaXml.Field.Attributes["List"].'#text' $newLookupListID
  54. if($schemaXml.Field.Attributes["List"].'#text' -ne $newLookupListID)
  55. {
  56. Write-Host "Found issue with List, Is:" $schemaXml.Field.Attributes["List"].'#text' "should be" $newLookupListID -f red
  57. $schemaXml.Field.Attributes["List"].'#text' = $newLookupListID
  58. $requiresUpdate = $true
  59. }
  60. if($requiresUpdate) {
  61. $siteColumn.SchemaXml = $schemaXml.OuterXml
  62. Write-Host "Fixing the list lookup Id to "$schemaXml.OuterXml -f DarkGray
  63. $siteColumn.Update()
  64. $siteCtx.ExecuteQuery()
  65. Write-Host "Lookup Field has fixed...Enjoy"
  66. }
  67. }
Once this script runs successfully then the lookup column will restore it on the corrupt column list.
Repair Lookup Column In SharePoint Online Using PowerShell