SharePoint Online: Remove a Site Column from Content Type using PowerShell

Requirement: Remove a Site Column from Content Type in SharePoint Online.

How to Remove a Column from Content Type in SharePoint Online?

When you remove a site column from a content type, It does not delete the column from SharePoint Online. It simply removes the site column’s association from the particular content type’s definition. To remove a column from the content type, follow these steps:

  • Go to Site Settings >> Site Content Types (If its List level, Go to List Settings)
  • Pick the content type from the page, In the columns section, Click on the column to remove from the content type.
  • In the change content type page, click on “Remove” button and confirm the prompt to delete the column from the content type.
    sharepoint online remove column from content type

SharePoint Online: Remove a Column from Content Type using PowerShell

Here is how to remove a column from content type using PowerShell

#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-ColumnFromContentType()
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ContentTypeName,
        [Parameter(Mandatory=$true)] [string] $SiteColumnName

    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 content type from web
        $ContentTypeColl = $Ctx.Web.ContentTypes
        #Check if the content type exists in the site        
        $ContentType = $ContentTypeColl | Where {$_.Name -eq $ContentTypeName}
        If($ContentType -eq $Null)
            Write-host "Content Type '$ContentTypeName' doesn't exists in '$SiteURL'" -f Yellow

        #Get the column to delete from content type
        $ContentTypeFieldColl =  $ContentType.Fields

        $SiteColumn = $ContentTypeFieldColl | Where {$_.Title -eq $SiteColumnName }
        if($SiteColumn -eq $null)
            Write-host "Site Column '$SiteColumnName' 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($SiteColumn.Id)

            Write-host "Site Column '$SiteColumnName' deleted from '$ContentTypeName' successfully!" -ForegroundColor Green
    Catch {
        write-host -f Red "Error Deleting Site Column from Content Type!" $_.Exception.Message

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

#Call the function
Remove-ColumnFromContentType -SiteURL $SiteURL -ContentTypeName $ContentTypeName -SiteColumnName $SiteColumnName

PnP PowerShell to Remove Column from Content Type in SharePoint Online

#Config Variables
$SiteURL = ""
$ContentTypeName ="Crescent Invoice Template V2"
$FieldName ="Project_x0020_Manager"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the Client Context
$Context = Get-PnPContext
#Get the content type
$ContentType = Get-PnPContentType -Identity $ContentTypeName

    #Get the Field from Content type
    $Field = $ContentType.Fields.GetByInternalNameOrTitle($FieldName)

    #Remove the Field from content type
    $ContentType.Update($False) #Update children

    Write-host -f Green "Field '$FieldName' has been removed from Content Type!"

Alternatively, you can use “Remove-PnPFieldFromContentType” cmdlet in PnP PowerShell. Here is how:

Remove-PnPFieldFromContentType -Field $FieldName -ContentType $ContentTypeName

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