This the scenario:

I have created a new LookupField (Content Type) called MyLookupField which derives from SPFieldLookup as shown below:

public class MyLookupField : SPFieldLookup

Here's my question: With PowerShell how do I create a SharePoint list column using my new content type MyLookupField which derives from SPFieldLookup? The method to add column to a list in PowerShell expects an enumeration which is obviously does not have my derived MyLookUpField field.

$myList.Fields.Add("MyLookup", [Microsoft.SharePoint.SPFieldType]::?????,$true)

With PowerShell how do I create a SPList column and associate it to a content type?

$web = Get-SPWeb <url>

$childList = $web.Lists["Employees"]    
$parentList = $web.Lists["Countries"]

$childList.Fields.AddLookup("Country", $parentList.ID, $true)

$field = $childList.Fields.getfield("Country")

$fieldLink = New-Object Microsoft.SharePoint.SPFieldLink($field)

$ctype = $childList.ContentTypes["MyLookupField"]



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.