SharePoint Online: Get List Content Types using PowerShell

Requirement: Get All Content Types from a SharePoint Online List.

How to Get SharePoint Online List Content Types?

Content types in SharePoint Online define the metadata, workflows, and behaviors associated with a particular type of content, such as list items and documents. Are you looking for a way to get content types from a SharePoint Online list? If so, PowerShell is the answer. This blog post will show you how to use PowerShell to easily retrieve a list of content types associated with a SharePoint Online list or document library.

To get all content types of a SharePoint List or library,

  1. Navigate to the list or document library in the browser
  2. Click on Setting gear >> Choose “List Settings”
  3. You’ll find all list content types on the List settings page under the “Content Types” section.
    SharePoint Online Get List Content Types using PowerShell

SharePoint Online: PowerShell to Get List Content Types

Here is the PowerShell to get a list of content types in the SharePoint Online list:

#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"
 
#Set parameter values
$SiteURL="https://Crescent.sharepoint.com/"
$ListName="Projects"

#Get Credentials to connect
$Cred= Get-Credential
  
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
#Get the List
$List = $Ctx.Web.lists.GetByTitle($ListName)

#Get All content types of the list
$ContentTypes = $List.ContentTypes
$Ctx.Load($ContentTypes)
$Ctx.ExecuteQuery()

#Get Content Type Details
$ContentTypes | Select Name,Description, Group, ID

This script will retrieve all content types from your SharePoint Online list and display their name, description, group, and IDs. Here is the output:

sharepoint online powershell get list content types

Similarly, to get content types from a SharePoint Online list using PnP PowerShell, use:

#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$ListName = "Projects"
$ContentTypeName = "Crescent Projects V2"

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

#Get all content types from list
$ListContentTypes = Get-PnPContentType -list $ListName
$ListContentTypes | Select Name, ID

#To get a specific content type from a list, use:
$ListContentType = Get-PnPContentType -list $ListName -Identity $ContentTypeName

To get content types of all lists in SharePoint Online, use: SharePoint Online: Get Content Type usage using PowerShell

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!

Leave a Reply

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