Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a custom content type and I added this content type to a list. I now want this list to only use the custom content type and I want to remove the built-in "Item" content type.

I tried
$spHeaderList.ContentTypesEnabled = $true $spHeaderList.ContentTypes.Delete($spItemContentTypeId) $spHeaderList.Update()

I used $spItemContentTypeId as 0x01 and as $ItemID = [Microsoft.SharePoint.SPBuiltInContentTypeId]::Item $spItemContentType = $spWeb.ContentTypes[$ItemID]

but still could not get it to work. I always get the message that "Cannot convert null to type "Microsoft.SharePoint.SPContentTypeId"

Any clues?

I am using SP2010

share|improve this question
add comment

1 Answer

Don't make it harder on yourself than needed - instead of trying to figure out the IDs yourself, just look for the plain text name you know. There is a good tutorial on how to remove a content type via powershell from a list here: Add and remove site content types from SharePoint lists using PowerShell.

Please note that you can only remove the "Item" content type from your list if there are no objects with the item content type currently in your list. The Powershell script blatantly copied below:

#Get site object and specify name of the library to look for in each site
$site = Get-SPSite http://YOURSITEHERE
$lookForList = "YOURLISTHERE”

#Walk through each site and change content types on the list specified
$site | Get-SPWeb -Limit all | ForEach-Object {

    write-host "Checking site:"$_.Title

    #Check list exists
    $docLibrary = $_.Lists[$lookForList]

    #Remove unwanted content types from the list
    if($docLibrary -ne $null)
    {
        $ctToRemove = $docLibrary.ContentTypes["Item"]
        write-host "Removing content type" $ctToRemove.Name "from list" $docLibrary.Title
        $docLibrary.ContentTypes.Delete($ctToRemove.Id)
        $docLibrary.Update()
    }
    else
    {
        write-host "The list" $lookForList "does not exist in site" $_.Title
    }
}
#Dispose of the site object
$site.Dispose()
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.