Find content type ID in SharePoint Online using PowerShell
Inspired by a very nice article on content type ID in SharePoint server available here, the author decided to post a version for SharePoint Online.
PowerShell scripting with CSOM
There are no out-of-the-box cmdlets for SharePoint Online. One of the options is CSOM:
- Download and install SharePoint Online SDK.
- Open Powershell ISE.
- Add the SDK libraries:
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"
- Save the following information into variables. Bear in mind that you are connecting to any given SharePoint site or subsite, and -admin is not required in the URL:
$Username="t@trial876.onmicrosoft.com"
$Password=Read-Host -Prompt "" -AsSecureString
$Url="https://trial876.sharepoint.com"
- Create context:
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $Password)
$ctx.ExecuteQuery()
- Load the site and its content types:
$ctx.Load($ctx.Web)
$ctx.Load($ctx.Web.ContentTypes)
$ctx.ExecuteQuery()
- Now you have all the data. Now it depends on you and your requirements what you want to display next.
All content types and their IDs:
foreach($cc in $ctx.Web.ContentTypes)
{
Write-Host $cc.Name " ID: " $cc.ID
}
Content type by a given name:
foreach($cc in $ctx.Web.ContentTypes)
{
if($cc.Name -eq "East Asia Contact")
{
Write-Host $cc.Id
}
}
PowerShell SPOMod
Prerequisites
1. Download and install SharePoint Online SDK.
2. Download SPOMod available here.
3. Open SPOMod current file (in ISE or NotePad) and scroll down to the following lines:
# Paths to SDK. Please verify location on your computer.
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"
- Make sure that the paths correspond to the locations of SDK on your machine. Most often you need to change 16 into 15.
- Save the file.
- Open PowerShell as an Administrator.
- Run Import-Module PathToTheSPOModFile
- Run Connect-SPOCSOM cmdlet.
List Content Type
To see all properties of the content type, enter:
Get-SPOContentType -ListTitle MyListTitle
To see only IDs, enter:
Get-SPOContentType -ListTitle ghgh | select name, id
Site Content Type
To see all content types with all their properties, enter:
Get-SPOContentType
To see only content types and their respective ids:
Get-SPOContentType | select name, id
You can add | ft -autosize to see untruncated results in the Shell:
Get-SPOContentType | select name, id | ft -AutoSize
From a subsite
Get-SPOContentType -Available | select name, id | ft -Autosize
By name
Get-SPOContentType | where {$_.Name -eq "Task"} | select id
References
Articles
Other articles on content types and PowerShell:
- SharePoint Online content types in Powershell: Add
- SharePoint Online content types in Powershell: Get
- SharePoint Online content types in Powershell: Edit
- SharePoint Online content types in Powershell: Group property
- SharePoint Online content types in Powershell: Fields vs Field Links
- SharePoint Online content types in Powershell: Known Errors
Downloads
Scripts on content types available from TechNet Gallery:
Adding
- SharePoint Online: Create a content type using Powershell
- Create content type and add directly to SPO list using Powershell
- Create and add content type to a content type hub SharePoint Online
- Create content type and add it to all lists in one site
- Add Content Type to Task Lists
- Add Content Type to Lists with Workflows
- Add existing content type directly to SPO list using Powershell
Getting
- Get all properties of all content types in a SharePoint site
- Get All Properties of All Content Types (Detailed)
- Get All Properties of All Content Types in All Lists (Detailed) across one site
- Get properties of a single content type by its ID
- Get content types belonging to a group
- Get All Hidden Content Types added to the site
- Get Single Content Type - Array Method
- Get Names of all content types added to your SPO lists
- Get Names of All Content Types
- Get Names of all Available Content Types
- Get Content Types Derived From One Parent
- Get Content Types Derived From One Parent 2
- Get content types which cannot be modified
- Get Content Types with a particular column
- SharePoint Online: Get the custom form display url using Powershell
- Find Custom Display Forms Deployed on your lists using Powershell
- Verify the content types used in your lists against the default ones
- Retrieve all Content Types from a Content Type Hub and their DisplayFormTemplate
Editing
- "Unseal" sealed content types in SharePoint Online site collection
- Modify the description of a list content type using Powershell
- Modify the description of a site content type using Powershell
- Unable to view items: modify the DisplayFormUrl back to default one
- Modify the Display Form Template Name
- Reset default content types
- Add column (fieldlink) to a content type using Powershell
- Assign your Content Types back to their default Groups using Powershell
Content Type Management
- Allow content type management for all lists in site collection using Powershell
- Allow content type management for all lists in a site using Powershell
- Set content type management setting for SharePoint Online list using Powershell
- Custom Powershell cmdlet Set-SPOList -ContentTypesEnabled
Related Scripts
- SharePoint Online: Check content types added to your lists
- SharePoint Online: Check content types added to your lists (recursive)
- Get a report on lists where a given content type is added
- SharePoint Online: Remove a content type from all lists in a site collection
- Compare Web.AvailableContentTypes vs Web.ContentTypes