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 a List in SharePoint Online?

Content types are reusable collections of metadata that define the columns and behavior of items within a list or library. There may be situations where you need to remove a content type from a list or library. You can remove a content type associated with a list in SharePoint Online when you no longer need it. In this article, we will guide you through the process of removing a content type from a SharePoint Online list using PowerShell.

To delete a content type from the SharePoint Online list, do the following:

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

Keep in mind that this will only remove the content type from the list – it will not delete the content type itself. If you need to delete the content type entirely, you’ll need to do that from the site settings page.

Delete Content Type from List using PowerShell in SharePoint Online

Content types not used in lists or libraries can be deleted. To remove a content type from a SharePoint Online list, use this PowerShell script. You need to specify the site URL, content type name, and list name as parameters.

#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()
{ 
    param
    (
        [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)
        $Ctx.Load($List)

        #Get the content type from list
        $ContentTypeColl = $List.ContentTypes
        $Ctx.Load($ContentTypeColl)
        $Ctx.ExecuteQuery()

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

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

#Set parameter values
$SiteURL="https://crescent.sharepoint.com"
$ListName="Projects"
$ContentTypeName="ProjectMilestone"

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

To confirm that the content type has been successfully removed from the list, navigate to the list settings in the SharePoint Online site and check the list of content types. The content type you removed should no longer be listed.

Delete Content Type from SharePoint Online List using PnP PowerShell:

As an administrator, you may need to delete a content type from the SharePoint Online list. Let me show you how to connect to your SharePoint Online list or library and remove a content type using PnP PowerShell:

#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$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
$ListContentType.DeleteObject() 
$Context.ExecuteQuery()

You can also remove the content type from a list using Remove-PnPContentTypeFromList cmdlet:

#Set Variables
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"
$ListName = "Projects"
$ContentTypeName ="Crescent Project Proposal V2"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

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

By following the steps outlined in this article, you can easily remove content types from lists as needed. This allows you to maintain a clean and organized SharePoint Online environment, ensuring that your lists and libraries remain relevant and up-to-date for your users.

Please note, you can’t remove the 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 the content type from the 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 - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *