SharePoint Online: Get List Content Types using PowerShell

Requirement: Get All Content Types from a SharePoint Online List

SharePoint Online List Content Types

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 get content types from a SharePoint Online list.

To get all content types of a  SharePoint List or library, go to List Settings, and you’ll find all content types of the list under the “Content Types” section.

SharePoint Online Get List Content Types using PowerShell

SharePoint Online: PowerShell to Get List Content Types

#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

and 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 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