How to Get Content Type ID in SharePoint using PowerShell?

Requirement:
Typical usage of Content Types is reusable metadata in SharePoint. At times, You may need to get content type ID by name in order to assign the content type to lists and libraries programmatically. Let’s get content type ID in SharePoint 2016 using PowerShell.

How to find content type id in SharePoint List?

To get content type id from SharePoint interface:

  • Open your SharePoint List in browser >> click on “List Settings” from the List tab of the Ribbon
  • In the List Settings page click on your target content type under “Content types” – Assuming content types are enabled already.
  • Now, You’ll see the ID of the content type in the URL.The last part is the Content Type Id. E.g. https://intranet.crescent.com/_layouts/15/ManageContentType.aspx?List=%7BEE1EA017%2DD347%2D49E6%2D9FE2%2D2CA7D1CB7B57%7D&ctype=0x01160074E6A09BFE52244F8ECB851FF74077FCsharepoint 2013 powershell get content type id

The same procedure applies to site content types as well. Go to Site settings >> Site Content Types >> Pick your content type >> The URL will have the “Ctype” parameter with the content type ID of the respective content type.

SharePoint 2016 PowerShell to get content type id:

Here is the SharePoint PowerShell to find content type by id.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Config Parameters
$WebURL="https://intranet.crescent.com"
$ListName="Projects"
$ContentTypeName="Contact Project"

#Get the Web, List and Content Type objects
$Web = Get-SPWeb $WebURL
$List = $Web.Lists.TryGetList($ListName)
#Get the content Type from its name
$ContentType = $List.ContentTypes | Where {$_.Name -Match $ContentTypeName}

#sharepoint get content type id by name
Write-Host $ContentType.ID 

Similarly, to get the site content type id in SharePoint 2013 using PowerShell, use:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Config Parameters
$WebURL="https://intranet.crescent.com"
$ContentTypeName="Crescent Configuration Entry"

#Get the Web, List and Content Type objects
$Web = Get-SPWeb $WebURL
#Get the content Type from its name
$ContentType = $Web.ContentTypes | Where {$_.Name -Match $ContentTypeName}

#sharepoint get content type id by name
Write-Host $ContentType.ID
How to get a content Type by ID?
$CT = $Web.ContentTypes | Where {$_.ID -eq “0x01005B3FBCA1E5314D57B4198D54F9F9B9CD”}

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.