Skip to content

Instantly share code, notes, and snippets.

@empo empo/0.md
Last active Feb 18, 2016

Embed
What would you like to do?
SharePoint 2013 Powershell How To Update Modify Lookup Column Field References

SharePoint 2013 Powershell How To Update Modify Lookup Column Field References

When you delete a list referenced from a lookup field, the field stops working, even if you recreate the list with the same name. This is due to the fact that the lookup field referneces the list by ID and not by Title.

Even if from UI interface you can't edit a column definition of a lookup field, you can easily change the lookup definition using Powershell.

The following snippet shows how to change the lookup list and display value of a site column definition. The trick is to work on the XMLSchema of the field and then update the field definition. Note: if you have defined in your lookup field to show additional fields, you have to reset the lookup list for these fields too.

$sitecol = Get-SPWeb http://yousite/coll
$lookup = $sitecol.Fields["YourLookupField"]
$schema = [xml] $lookup.SchemaXml
# in this example i'm going to reset the lookup list
$schema.Field.Attributes["List"].Value = "{" + $sitecol.Lists["YouNewLookupList"].ID + "}"
# you can also change the display value for the lookup
$schema.Field.Attributes["ShowField"].Value = "Title"
$lookup.SchemaXml = $schema.OuterXml
$lookup.Update($true)
$sitecol.Dispose()
# if you have set to show additional fields for the lookup, they can be found as "YourLookupField:FieldName"
# you can list them as follows:
$sitecol.Fields | ? { $_.Title -match "YourLookupField" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.