Añadir Site Column del tipo Lookup Field via PowerShell

Con este script podeis crear columnas del tipo Lookup a una lista en SharePoint:

$web = Get-SPWeb "WEB_URL"
$list = $web.Lists["LIST_NAME"]
$lookupFieldXML = '<Field
Type="Lookup"
DisplayName="NEW_FIELD"
Required="FALSE"
EnforceUniqueValues="FALSE"
List="{LIST_ID}"
ShowField="Title"
UnlimitedLengthInDocumentLibrary="FALSE"
RelationshipDeleteBehavior="None"
SourceID="LOOKUPLIST_ID"
StaticName="NEW_FIELD"
Name="NEW_FIELD"
ShowInDisplayForm="TRUE"
ShowInEditForm="TRUE"
ShowInNewForm="TRUE"
RowOrdinal="0" />'
$a = $list.Fields.AddFieldAsXml($lookupFieldXML, $true, [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView);
$list.Update();
$web.Dispose();

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.