I'm trying to add some custom property to list content type at SharePoint Online site by following script:

$context=New-Object Microsoft.SharePoint.Client.ClientContext($URL)
$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword)

$web = $context.Web

$lib = $web.Lists.GetByTitle("Document Library")


$cts = $lib.ContentTypes

ForEach ($c in $cts) {
     if($c.Name -eq "Document") {
        $ct = $c

$fields = $lib.Fields

ForEach ($fl in $fields) {
    if($fl.Title -eq "Keyword") {
        $keyword = $fl

$link=new-object Microsoft.SharePoint.Client.FieldLinkCreationInformation


But I got exception below while executing.

Exception setting "Field": "Cannot convert the
"Microsoft.SharePoint.Client.FieldText" value of type
"Microsoft.SharePoint.Client.FieldTe xt" to type
"Microsoft.SharePoint.Client.Field"." At D:\tmp\AddContentType.ps1:47
+ [cultureinfo]::CurrentUICulture = 'en-US'; $link.Field=$keyword
+                                            ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting   Cannot convert argument "parameters", with value:
"Microsoft.SharePoint.Client.FieldLinkCreationInformation", for "Add"
to type "Microsof t.SharePoint.Client.FieldLinkCreationInformation":
"Cannot convert the
"Microsoft.SharePoint.Client.FieldLinkCreationInformation" value o f
type "Microsoft.SharePoint.Client.FieldLinkCreationInformation" to
type "Microsoft.SharePoint.Client.FieldLinkCreationInformation"." At
D:\tmp\AddContentType.ps1:51 char:1
+ $ct.FieldLinks.Add($link)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

Samples I have found so far are all about adding site columns to content type, not list column. Is there any way to add list column to list content type via PowerShell?

Thanks in advance.


1 Answer 1


Try using below code:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Function Add-ColumnToListContentType()
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ListName,
        [Parameter(Mandatory=$true)] [string] $ContentTypeName,
        [Parameter(Mandatory=$true)] [string] $ColumnName,
        [Parameter(Mandatory=$false)] [bool] $IsSiteColumn=$True

    Try {
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials

        #Get the List
        $List = $Ctx.Web.Lists.GetByTitle($ListName)

        #Get the content type from list
        $ContentTypeColl = $List.ContentTypes

        #Check if the content type exists in the list       
        $ContentType = $ContentTypeColl | Where {$_.Name -eq $ContentTypeName}
        If($ContentType -eq $Null)
            Write-host "Content Type '$ContentTypeName' doesn't exists in '$ListName'" -f Yellow

        #Get the column to add: Either site column or existing list's column
            $ColumnColl = $Ctx.Web.Fields
        else #List Column
            $ColumnColl = $List.Fields
        $Column = $ColumnColl | Where {$_.Title -eq $ColumnName}

        #Check if given column exists
        if($Column -eq $Null)
            Write-host "Column '$ColumnName' doesn't exists!" -f Yellow
            #Check if column already added to the content type
            $FieldCollection = $ContentType.Fields
            $Field = $FieldCollection | Where {$_.Title -eq $ColumnName}
            if($Field -ne $Null)
                Write-host "Column '$ColumnName' Already Exists in the content type!" -f Yellow

            #Add field to content type
            $FieldLink = New-Object Microsoft.SharePoint.Client.FieldLinkCreationInformation
            $FieldLink.Field = $Column

            Write-host "Column '$ColumnName' Added to '$ContentTypeName' Successfully!" -ForegroundColor Green
    Catch {
        write-host -f Red "Error Adding Column to Content Type!" $_.Exception.Message

#Set parameter values
$ColumnName="Head Count"

#Call the function
Add-ColumnToListContentType -SiteURL $SiteURL -ListName $ListName -ContentTypeName $ContentTypeName -ColumnName $ColumnName


SharePoint Online: Add Column to List Content Type using PowerShell

  • Thank you for quick response. I tried your script, but got same exception. Exception setting "Field": "Cannot convert the "Microsoft.SharePoint.Client.FieldText" value of type "Microsoft.SharePoint.Client.FieldText" to type "Microsoft.SharePoint.Client.Field"."At D:\tmp\AddContentType.ps1:43 char:1+ $FieldLink.Field = $Column It seems the object type is different between site column and list column, isn't it? Is it possible to cast FieldText type to Field type??
    – mimicat
    Feb 19, 2020 at 8:03
  • Microsoft.SharePoint.Client.FieldText class is inherited from Microsoft.SharePoint.Client.Field. what is the date type of your column? Single Line of text?? Feb 20, 2020 at 7:05
  • 1
    I did some investigation and found the cause of error is I had installed multiple version of SharePoint online csom. After unistalling older version, I succeeded to execute your code and got to add list column to content type. Thank you very much!
    – mimicat
    Feb 20, 2020 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.