Geeks With Blogs
SharePoint Wiki! Sharing is gaining...
Are you stuck with the error: "Error: content type in use."
You have to delete all of the content type's children and its usage before you can proceed.
Once the dependencies are gone, you can delete the custom site content type itself.

Here's a mock code that I wrote.

$sitename = $args[0]
$contentType = $args[1]

$web = Get-SPWeb $sitename
$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()


...

If this still doesn't solve your problem read on:

Try: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spcontenttypecollection.delete.aspx

If the "Usages.Count" is = 0. 

Make sure the CT is not under either "Recycle BIN" or "Site Collection Recycle Bin".

So: 

  • Delete from site recycle bin.
  • Delete from Site Collection > Site Settings > Site Collection Administration > Recycle Bin.
  • Delete from End User Recycle Bin Items.
  • Delete from "Deleted From End User Recycle Bin."
Posted on Wednesday, July 11, 2012 6:30 AM | Back to top


Comments on this post: PowerShell to delete usage of Content Type(s) and delete the Content Type

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © KunaalKapoor | Powered by: GeeksWithBlogs.net