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?
-
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.– ChristofferCommented Feb 22, 2016 at 14:01
2 Answers
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
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()