SharePoint 2010 + PowerShell: View Dependencies of Content Types (aka Content Type Usage)

Earlier today, I created some test Content Types while playing around with the fancy new Content Organizer. I ran into a few errors, though, and subsequently wanted to delete the dummy content types to start over. I was unable to, however, because the content types were still in use. By what? I didn’t know.

Too bad SharePoint doesn’t have a feature similar to SQL Server Management Studio’s “View Dependencies.” Till it does.. here is a PowerShell script that does the trick.

$sitename= "http://sharepoint"
$contentType = "My Custom Content Type"

$web = Get-SPWeb $sitename
$ct = $web.AvailableContentTypes[$contentType]
$ctusage = [Microsoft.SharePoint.SPContentTypeUsage]::GetUsages($ct)
     foreach ($ctuse in $ctusage) {
          $ctuse.Url
     }

$web.Dispose()

 
Looking for content type usage within subsites? A more thorough script can be found at StackExchange.

Chrissy is a Cloud and Datacenter Management MVP who has worked in IT for over 20 years. She is the creator of the popular SQL PowerShell module dbatools, and holds a number of certifications, including those relating to SQL Server, Linux, SharePoint and network security. You can follow her on Twitter at @cl.

Posted in PowerShell, SharePoint

Leave a Reply

Your email address will not be published. Required fields are marked *

*