Create a SharePoint 2010 Content Type using Powershell

Creating a content type using powershell:

$site = get-spsite $url

$web = $site.openweb()

$ctypeName = “myName”

$ctypeParent = $web.availablecontenttypes[“Document”]

$ctype = new-object Microsoft.SharePoint.SPContentType($ctypeParent, $web.contenttypes, $ctypeName)

$web.contenttypes.add($ctype)

$web.fields.add(“myField”, ([Type]”Microsoft.SharePoint.SPFieldType”)::Text, $false)

$field = $web.fields.getfield(“myField”)

$fieldLink = new-object Microsoft.SharePoint.SPFieldLink($field)

$ctype.fieldlinks.add($fieldLink)

$ctype.Update()

$web.Dispose()

$site.Dispose()

Advertisements

5 Responses to Create a SharePoint 2010 Content Type using Powershell

  1. Sanjay says:

    This is a good info here but what if i need to add columns to the content type i created and their types? I need it desperately, please help me out.

  2. Jaclyn says:

    Hi Sanjay,

    I updated my previous blog post to include how to add columns to the content type!

  3. sanjayrimal says:

    Thanks Jacklyn, I appreciate your effort. But was wondering where can i find the list of all the types that can be used for field types, like this example shows for the text right? Thanks ahead of time.

  4. Pingback: Create a SharePoint 2010 Content Type using Powershell « SharePoint Thoughts « sysadmin by chance

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: