kwizcom banner advertisement

How to Get Content Type ID in SharePoint using PowerShell?

Requirement:
A 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. Lets get content type id in SharePoint 2013 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. http://intranet.crescent.com/_layouts/15/ManageContentType.aspx?List=%7BEE1EA017%2DD347%2D49E6%2D9FE2%2D2CA7D1CB7B57%7D&ctype=0x01160074E6A09BFE52244F8ECB851FF74077FCsharepoint 2013 powershell get content type id
Same procedure applies for Site content Types as well. Go to Site settings >> Site Content Types >> Pick your content type >> The URL will have "Ctype" parameter with the content type ID of the respective content type.

SharePoint 2013 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="http://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="http://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"}

Tags: sharepoint powershell find content type by id,  find content type id sharepoint 2013, get content type id sharepoint 2013 powershell, how to get content type id from sharepoint, sharepoint get content type id programmatically
How to Get Content Type ID in SharePoint using PowerShell? How to Get Content Type ID in SharePoint using PowerShell? Reviewed by Salaudeen Rajack on October 16, 2016 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.