TwitterLinkedInBlog

Thursday, February 26, 2015

PowerShell - Find Content Type in Use

$siteURL = http://sample/
$contentType = "Sample"
$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 "(Would have) Deleted -" $contentType "- content type from -" $ctuse.Url "-"
        }
#$ct.Delete()
Write-host "(Would have) Deleted -" $contentType "- from site."
} else { Write-host "Nothing to delete." }
$web.Dispose()


Reference:
http://stackoverflow.com/questions/6427315/unable-to-delete-sharepoint-2010-contenttype-contenty-type-in-use

No comments: