SharePoint Online: Remove Content Type from List using PowerShell

Requirement: Remove a Content type from SharePoint Online List.

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

Content types that are not in use in lists or libraries can be deleted. To delete a content type from the SharePoint Online list, do the following:

  • Login to your SharePoint Online site >> Navigate to the list or library settings
  • Under “Content Types”, Click on the appropriate content type name that you wish to remove from the List.
  • On the List Content Type page, click on the “Delete this content type” link and confirm the prompt once to remove the content type from the list
    sharepoint online powershell remove content type from list

Delete Content Type from List using PowerShell in SharePoint Online

To remove a content type from SharePoint Online list, use this PowerShell script.

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

    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

        #Get the content type to remove
        $CTypeToRemove = $ContentTypeColl | Where {$_.Name -eq $ContentTypeName}
        If($CTypeToRemove -ne $Null)
            #Remove content type from list

            Write-host "Content Type '$ContentTypeName' Removed From '$ListName'" -f Green
            Write-host "Content Type '$ContentTypeName' doesn't exist in '$ListName'" -f Yellow
    Catch {
        write-host -f Red "Error Removing Content Type from List!" $_.Exception.Message

#Set parameter values

#Call the function
Remove-ContentTypeFromList -SiteURL $SiteURL -ListName $ListName -ContentTypeName $ContentTypeName

Delete Content Type from SharePoint Online List using PnP PowerShell:

#Config Variables
$SiteURL = ""
$ListName ="Project Documents"
$ContentTypeName ="Invoice Template V2"

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

#Get the content type from list
$ListContentType = Get-PnPContentType -list $ListName -Identity $ContentTypeName
#Delete the content type from List

You can also remove content type from list as:

#Set Variables
$SiteURL = ""
$ListName = "Projects"
$ContentTypeName ="Crescent Project Proposal V2"

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

#Remove content type from List
Remove-PnPContentTypeFromList -List $ListName -ContentType $ContentTypeName

Please note, you can’t remove content type from a list if the list has any items created based on the particular content type you wish to remove! This could result in “Content Type is still in use” error both from SharePoint UI or using PowerShell to remove content type from list. Here is another post to help: Getting “List content type is still in use” in SharePoint Online? Find out where using PowerShell

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