SIGN UP MEMBER LOGIN:    
ARTICLE

Set-SPListContentTypes PowerShell Cmdlet

Posted by Vijai Anand Articles | Windows PowerShell April 18, 2011
A custom Powershell cmdlet to add, remove and change the order of the content types in SharePoint 2010 list
Reader Level:

1.0 Description:

A custom Powershell cmdlet to add, remove and change the order of the content types in SharePoint 2010 list

2.0 Set-SPListContentTypes

NAME

    Set-SPListContentTypes

SYNTAX

    Set-SPListContentTypes [-url] <String> [-ListName] <String> [[-ContentTypeToAdd] <List`1>] [[-ContentTypeToRemove] <List`1>]   [[-ContentTypeOrder] <List`1>]   


Parameters

Parameter

Required

Type

Description

Url

Required

System.String

Specifies the URL of the site collection.

ListName

Required

System.String

Specifies the list name.

ContentTypeToAdd

Optional

System.Collections.Generic.List<T>

Add list of content types to the SharePoint list.

ContentTypeToRemove

Optional

System.Collections.Generic.List<T>

Remove list of content types from the SharePoint list.

ContentTypeOrder

Optional

System.Collections.Generic.List<T>

Change the order of the content types in the list.

Detailed Description

EXAMPLE 1

Set-SPListContentTypes http://sitename/sites/test -ListName "tl" – ContentTypeToAdd @("ct1","ct2") – ContentTypeToRemove @("Content1","Content2") – ContentTypeOrder @("ct2","ct1")

The above cmdlet will

  • Add the content type's ct1 & ct2 to the list "tl".
  • Remove the content types Content1 & Content2 from the list "tl".
  • Content types Order will be ct2, ct1.
  • Default content type will be first one ct2.

    ss.gif

3.0 Register the cmdlet:

  • Unzip the source code.
  • Go to the installer folder.
  • Run Install.bat.
  • anavijai.SP2010.PowerShell.dll will be installed in the gac.
  • Go to 14\CONFIG\POWERSHELL\Registration and check whether anavijaiSP2010Cmdlet.xml is available.
  • Run "SharePoint 2010 Management Shell" as administrator.
  • Check whether the cmdlet is registered by executing the following commands.
    - Get-Command Set-SPListContentTypes
    - Help SPListContentTypes

erver'>
Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor