Find Lists or Libraries Using a Content Type in SharePoint with PowerShell

The following PowerShell script will loop through all the lists in a given site and look for a particular content type.  This is useful if you ever need to report on how many lists are using a content type, or you're just curious.This script takes 2 arguments: Web URL - This is

 
 
 
 
 
5 Star
(1)
1,852 times
Add to favorites
SharePoint
7/23/2013
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Error when I use this script
    2 Posts | Last post January 21, 2015
    • I use the following command as specified PS P:\> C:\scripts\Find-Content-Types.ps1 "{weburl}" "{custom site content type}"
      
      and I get the following error:
      C:\scripts\Find-Content-Types.ps1 : Exception has been thrown by the target of an invocation.
      At line:1 char:34
      + C:\scripts\Find-Content-Types.ps1 <<<<  "{weburl}" "{custom site content type}"
          + CategoryInfo          : NotSpecified: (:) [Find-Content-Types.ps1], TargetInvocationException
          + FullyQualifiedErrorId : System.Reflection.TargetInvocationException,Find-Content-Types.ps1
    • You need to provide the URL to the site and the ContentType name in the call:
      
      C:\scripts\Find-Content-Types.ps1 'http://YOURDOMAIN/YOURSITE' 'CONTENTTYPENAME' 
      
  • Why not use the SPContentTypeUsage class?
    2 Posts | Last post August 20, 2013
    • http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spcontenttypeusage.aspx
      should be more efficient than a triple-nested foreach loop.
    • Cris, thanks for posting.  You are correct, I could eliminate one or more loops using the SPContentTypeUsage class.  The link you provided offers a great example, however my script differs a bit since it loops through all the webs in the site collection, instead of just the root web.
      
      So, this script could be modified easily to take advantage of the SPContentTypeUsage class and achieve the same result.
      
      Thanks!