SharePoint Online: Remove a Field from List Content Type using PowerShell

Requirement: Remove a field from SharePoint list content type in SharePoint Online.

PowerShell to Remove a Column from List Content Type in SharePoint Online:

#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 Remove-ColumnFromListContentType()
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ListName,
        [Parameter(Mandatory=$true)] [string] $ContentTypeName,
        [Parameter(Mandatory=$true)] [string] $ColumnName

    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 delete from content type
        $ContentTypeFieldColl =  $ContentType.Fields

        $Field = $ContentTypeFieldColl | Where {$_.Title -eq $ColumnName }
        if($Field -eq $null)
            Write-host "Column '$ColumnName' Doesn't exists in Content Type '$ContentTypeName'" -f Yellow
            #Get the field link from content type
            $FieldLinkColl = $ContentType.FieldLinks
            #Remove field from content type
            $FieldLink = $FieldLinkColl.GetById($Field.Id)

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

#Set parameter values
$ContentTypeName="Project Template"
$ColumnName="Project Department" #Display Name of the Field

#Call the function
Remove-ColumnFromListContentType -SiteURL $SiteURL -ListName $ListName -ContentTypeName $ContentTypeName -ColumnName $ColumnName

When you remove a column from content type, that field become a local column in any list or library which are using that content type!

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply