SharePoint Online: Add Content Type to List or Library using PowerShell

Requirement: SharePoint Online PowerShell to add a content type to the library.

How to add a content type to a list or library in SharePoint Online?

In SharePoint Online, you can add content types to a list to help define the type of information that is stored in the list. For example, you might add a content type for “Product” to a list that stores product information. This would allow you to create new items in the list that are automatically associated with the “Product” content type. This article will show you how to add a content type to a list in SharePoint Online.

Assuming you have the content type already created, here are the steps to add a content type to the list in SharePoint Online:

Step 1: Enable content types management for the list, if it’s not enabled already

Before adding a content type to a list or library, you must enable the list or library to support content types.

  1. Navigate to the List settings >> Click on the “Advanced Settings” link under General Settings.
  2. Set “Yes” for the “Allow management of content types?” option and hit the OK button at the bottom of the page to save your changes.

Step 2: Add Content Type to List or Library

Once content types are enabled, here is how you can add a content type to a list or library in SharePoint Online:

  1. Go to the list settings page again, You’ll find the “Content Types” group created with the default content type listed (E.g. You’ll find the “Item” content type listed for custom lists).
  2. Click on the “Add from existing site content types” link.
    sharepoint online powershell add content type to library
  3. From the Add content types page, select your content type to add and click on the “Add” button and then “OK” once.
    sharepoint online add content type to list
  4. That’s all. Now you’ll find the content type you added under the “Content Types” group of list settings.

Alright. Now, Let’s see how to add a content type to a list in SharePoint Online using PowerShell.

SharePoint Online PowerShell to Add Content Type to Library

Let’s add a content type to the list in SharePoint Online 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 Add-ContentTypeToList()
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ListName,
        [Parameter(Mandatory=$true)] [string] $CTypeName

    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)
        #Enable managemnt of content type in list - if its not enabled already
        If($List.ContentTypesEnabled -ne $True)
            $List.ContentTypesEnabled = $True
            Write-host "Content Types Enabled in the List!" -f Yellow

        #Get all existing content types of the list
        $ListContentTypes = $List.ContentTypes

        #Get the content type to Add to list
        $ContentTypeColl = $Ctx.Web.ContentTypes
        #Check if the content type exists in the site        
        $CTypeToAdd = $ContentTypeColl | Where {$_.Name -eq $CTypeName}
        If($CTypeToAdd -eq $Null)
            Write-host "Content Type '$CTypeName' doesn't exists in  '$SiteURL'" -f Yellow

        #Check if content type added to the list already
        $ListContentType = $ListContentTypes | Where {$_.Name -eq $CTypeName}
        If($ListContentType -ne $Null)
            Write-host "Content type '$CTypeName' already exists in the List!" -ForegroundColor Yellow
            #Add content Type to the list or library
            $AddedCtype = $List.ContentTypes.AddExistingContentType($CTypeToAdd)
            Write-host "Content Type '$CTypeName' Added to '$ListName' Successfully!" -ForegroundColor Green
    Catch {
        write-host -f Red "Error Adding Content Type to the List!" $_.Exception.Message

#Set parameter values
$ListName="Project Frosty"
$CTypeName="Project Template"

#Call the function
Add-ContentTypeToList -SiteURL $SiteURL -ListName $ListName -CTypeName $CTypeName

SharePoint Online PnP PowerShell to Add Content Type to Library

Here is how to add a content type to the document library in SharePoint Online using Add-PnPContentTypeToList PnP PowerShell:

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

#Get Credentials to connect
$Cred = Get-Credential

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
#Get the content type
$ContentType = Get-PnPContentType -Identity $ContentTypeName

    #Add Content Type to Library
    Add-PnPContentTypeToList -List $ListName -ContentType $ContentType
    Write-host -f Yellow "Could Not Find Content Type:"$ContentTypeName

Use -DefaultContentType switch to make the content type as default content type!

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

8 thoughts on “SharePoint Online: Add Content Type to List or Library using PowerShell

  • I am running into an issue where I have added a new Content Type to the Content Type Hub and now am wanting to add this to a list via powershell but I get the error “Could Not Find Content Type: *Name of content type*”.

    Is there a limitation where if the content type isn’t from the same source as the site the script doesn’t work

    • Yes! You have to run this once: Add-PnPContentTypesFromContentTypeHub -ContentTypes “Your-ContentType-ID” -Site “Your-Site-URL”

  • Hello Salaudeen,

    I sincerely appreciate your effort to help out, but I am a novice to PowerShell. I am really confused at this state as to how to go about the instructions given.

    Please I seek that you really help with a comprehensive way to go about the adding of content type to multiple document libraries.

    Thanks in anticipation to your true response.

  • Hello Salaudeen, Thank you for the response, it worked. But I still have concerns, which i seek you help out with.

    1) It prompts to sign in at every single library update, is there a way to go about/avoid it?
    2) I have about 400libraries to map the content type with and on different sites, is there a way to fetch the libraries name from an excel sheet, without entering them manually? Just the way you helped with creating multiple document libraries from an excel sheet to different sites.
    3) With Respect to (1) above, any mistake in a sign in, skips mapping of the content type to that particular library.
    4) Please help also with how to make the newly added content type the default for bulk update.

  • Hello Salaudeen,

    Please assist with if I have multiple libraries that I wish to add content type to.
    How do I go about that please?

    • If you know the library names, Just have your Library names in an Array and call the function with each library name! E.g.

      $Libraries = @(“Shared Documents”,”Branding”, “Team Docs”, “Products”)

      #Call the function to add content type to each document library
      $Libraries | ForEach-Object { Add-ContentTypeToList -SiteURL $SiteURL -ListName $_ -CTypeName $CTypeName }

      In case, You want to add to all available document libraries, use: How to Get All Document Libraries in a SharePoint Online site using PowerShell?

  • I am getting this error quiet recently, what could that be. I have successfully used the script before. Get-PnPContentType : Exception has been thrown by the target of an invocation. Thanks


Leave a Reply

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