7Sep/112
SharePoint 2010 + PowerShell: Delete Site Content Type
So first, you have to delete all of the content type's children or you'll receive the error "Error: content type in use." Once the dependencies are gone, you can delete the custom site content type itself.
$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()
Viola.



March 16th, 2012 - 12:47
Viola is a stringed instrument, I think you meant "Voila!"!!
March 19th, 2012 - 05:34
LOL! You're right. I shame my French heritage.