Thursday, May 23, 2013

Get the Site Content Type ID and feature ID in powershell

Sometimes the site content type ID is needed for development.
Go to Site Settings -> Site Content Type -> Content Type,
The content type ID is in the URL.

In Powershell, the following scripts are useful for the content types enumeration,
$sitecollection = Get-SPSite http://localhost
$sitecollection.RootWeb.ContentTypes include all the site content types

To get the specific content type by its ID
$c = $sitecollection.RootWeb.ContentTypes | where {$_.Id -eq "0x....."}

Also if create the custom content type page in visual studio, the elements.xml need to specify the PublishingAssociatedContentType such as,
<Property Name="PublishingAssociatedContentType" Value=";#Custom Article;#0x010100C568DB52D9D0A14D9.....;#" />

To list all the features
$site.Features to list all the site collection features.
$site.Features["GUID"] to get the specific feature

Also Get-SPFeature
Get-SPFeature -site http://site | where {$_.DisplayName -eq "..." }

There is a very useful tip to list the object properties
ps_object | Get-Member







 

No comments: