SharePoint Online: Create a Content Type using PowerShell

What is Content Type in SharePoint Online?

Content types are a set of columns grouped together to serve a specific purpose. Think about an Invoice template! Instead of you and your users end up creating different templates each time from the scratch, you can define an Invoice template once and your users can start consuming it at any number of lists or document libraries! In this way, you force standardization in your collaboration environment. Or think of a “Project Tracking” list with columns required to track projects for your organization. Instead of creating and adding each column for the Project tracking list every time, you’ll be able to simply utilize the project tracking content type template in any number of lists in few clicks.

SharePoint Online lists or document libraries can contain multiple content types. E.g. You can add multiple content types such as “Invoice”, “Proposal”, “Purchase Order”, etc to a library to organize everything related to a project as a single entity. Once you associate a content type with SharePoint online list or library, SharePoint lets you create new items of that content type from New Item command in that list or library. In the case of a document content type, you can also define a document template that will be the base for all the documents created from this particular content type.

As a best practice, content types should be ideally defined at the top site, independent of any list or library, So that it can be reused at any SharePoint site underneath or even across SharePoint site collections with content type hub.

How to Create a Content Type in SharePoint Online?

To add a content type in SharePoint Online, follow these steps:

  • Go to Site Settings >> Click on “Site Content Types” under “Web Designer Galleries” group.
  • In Site content types page, You”ll see the list of default content types like Item, Tasks, Document, etc grouped by sections. Click on “Create” link at the top.
  • Provide a name to your custom content type. Optionally you can enter the description for your new content type to make it clear.
  • Select the parent content type such as “Item” to which your content type is based on. You can either create a new content type group or select any existing.
    sharepoint online powershell create content type
  • Click OK to complete adding content type. Once the content type is created, The next step is to add required Site columns to the content type to make metadata available from the content type.

Now, lets see the PowerShell script to create content type programmatically in SharePoint.

SharePoint Online: Create Content Type using PowerShell

Here is how to create a content type 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 to turn ON Content Type in SharePoint Online list or library
Function Create-SPOContentType()
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $CTypeName,
        [Parameter(Mandatory=$true)] [string] $CTypeDesc,
        [Parameter(Mandatory=$true)] [string] $ParentCTypeName,
        [Parameter(Mandatory=$true)] [string] $CTypeGroup

    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 all content types from the site
        $ContentTypeColl = $Ctx.web.ContentTypes

        #Get the parent content type
        $ParentCType = $ContentTypeColl| Where {$_.Name -eq $ParentCTypeName}

        #Check if content type exists already
        $ContentType = $ContentTypeColl| Where {$_.Name -eq $CTypeName}

        If($ContentType -ne $Null)
            Write-host "Content type '$CTypeName' already exists!" -ForegroundColor Yellow
            #Specify properties for the new content type
            $CTypeCreationInfo=New-Object Microsoft.SharePoint.Client.ContentTypeCreationInformation

            # sharepoint online powershell create content type
            Write-host "Content Type '$CTypeName' Created Successfully!" -ForegroundColor Green
    Catch {
        write-host -f Red "Error Creating Content Type!" $_.Exception.Message

#Set parameter values
$CTypeDesc="Content type for Project template"
$CTypeGroup="Crescent Projects"

#Call the function
Create-SPOContentType -SiteURL $SiteURL -CTypeName $CTypeName -CTypeDesc $CTypeDesc -ParentCTypeName $ParentCTypeName -CTypeGroup $CTypeGroup

This script creates content type in SharePoint Online from the specified parent content type. Here in this example, I’ve created “Project” content type from “Item” content type which has “Title” as its default field. You may want to add additional fields to the content type. Here is how you can add columns to content type in SharePoint Online with PowerShell: How to Add a Site Column to Content Type in SharePoint Online using PowerShell?

Create Content Type in SharePoint Online using PnP PowerShell

#Config Variables
$SiteURL = ""
$ContentTypeName ="Crescent Projects V3"
$ContentTypeDescription ="Base Content Type for Crescent Projects Template"
$ContentTypeGroupName = "Crescent Content Types"

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

#Create Content Type
Add-PnPContentType -Name $ContentTypeName -Description $ContentTypeDescription -Group $ContentTypeGroupName

This creates a new content type based on the default parent “Item”.

create content type in sharepoint online using powershell

You can specify the parent content type as:

#Config Variables
$SiteURL = ""
$ContentTypeName ="Crescent Project Proposal V1"
$ContentTypeDescription ="Base Content Type for Crescent Project Prposal Template"
$ContentTypeGroupName = "Crescent Content Types"
$ParentContentTypeName ="Document" 

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

#Get the Parent content type
$ParentContentType = Get-PnPContentType -Identity $ParentContentTypeName

#Create Content Type
Add-PnPContentType -Name $ContentTypeName -Description $ContentTypeDescription -Group $ContentTypeGroupName -ParentContentType $ParentContentType

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