SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to delete a custom content type from all items that are using that content type in a list/library. Is that possible using powershell? if yes, then I want to know after deleting CT, which content type the existing items will use then? OR if there is any kind of problem will occur with those items?

share|improve this question
    
I think you will have to rethink your strategy.. a item need to always belong to a content type, and you will need to change content type on a item as you cannot simply delete it. And you need to make sure that the new content type matches the old when it comes to number of columns and columns types. – Christoffer Feb 22 at 14:01
up vote 2 down vote accepted

You CAN delete the content types from existing list, just make sure to apply default/other content type before deleting any existing content types. In fact, content type cannot be removed from a list if there are items currently using it in that list. Therefore, before you can attempt to remove a list content type, you must make sure that any items associated with it have either been assigned a different content type (see this article for details on how to do this) or deleted from the list completely.

Removing a content type from a list or library does not delete any items that were created from the content type.

I would suggest the following content type script to begin with

share|improve this answer

You cannot delete content types from items, instead you can remove content types from lists or web sites. If you would try to delete a content type which is still used, you would get an error: "Content Type in use". What you want to do (most probably) is lookup all items with the specific content type, change the content type for those items first and then remove the content type from lists and web sites.

You can check content type usage and delete the content type if it's not used with the following script:

$siteURL = "The Site url"
$contentType = "Content type Name"

$web = Get-SPWeb $siteURL
$ct = $web.ContentTypes[$contentType]

if ($ct) {
$ctusage = [Microsoft.SharePoint.SPContentTypeUsage]::GetUsages($ct)
      foreach ($ctuse in $ctusage) {
        $list = $web.GetList($ctuse.Url)
        $contentTypeCollection = $list.ContentTypes;
        $contentTypeCollection.Delete($contentTypeCollection[$ContentType].Id);
        Write-host "Deleted $contentType content type from $ctuse.Url"
        }
$ct.Delete()
Write-host "Deleted $contentType from site."

} else { Write-host "Nothing to delete." }

$web.Dispose()
share|improve this answer

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.