none
Find lists on site using a particular content type

    Question

  • Is there a way, using the GUI, to find out what lists in a site use a particular content type?

    If not, how can I accomplish this with PowerShell?

    Monday, July 22, 2013 4:23 PM

Answers

  • I have a similar script and when I ran Brandon's it looped through the same sites again and again. I'll admit I don't understand why! But here's my version.

    Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

    $webs = get-spsite [myurl] -Limit all | get-spweb -Limit all

    foreach ($web in $webs)
    {
      foreach ($lst in $web.lists)
      {
        foreach ($ctype in $lst.ContentTypes)
        {
          if ($ctype.Name -eq "myCTname")
          { $lst.DefaultViewUrl }
        }
      }
      $web.Dispose()
    }


    SharePoint Systems Officer, Capital Regional District, BC, Canada

    • Marked as answer by Elmo Watson Tuesday, July 23, 2013 12:45 PM
    Monday, July 22, 2013 10:37 PM

All replies

  • If you go to your list that contains items, you can modify the view to also show Content Type. So, if this was a task list, you will see "Task" as the Content type for those items.
    Monday, July 22, 2013 4:37 PM
  • That's basically my problem - - I don't know which list(s) use a particular content type.

    the only mechanism I have at this time is knowing the content type - but I need to find out which lists on the site use it.

    Monday, July 22, 2013 4:39 PM
  • Try this:

    $site = Get-SPSite("http://YOURSITE");
    foreach ($web in $site.AllWebs) {
    foreach ($list in $web.Lists) {
       $ctype = $web.ContentTypes["CONTENTTYPENAME"]
       $usages = [Microsoft.Sharepoint.SPContentTypeUsage]::GetUsages($ctype)
       foreach ($usage in $usages) {
          Write-Host $usage.Url
       }
    }
    }
    This will loop through all the subsites in the site URL supplied, and look for the content type supplied.  If it finds it it will spit out the relative path of the list/library.


    Brandon Atkinson
    Blog: http://brandonatkinson.blogspot.com

    Monday, July 22, 2013 4:52 PM
  • I have a similar script and when I ran Brandon's it looped through the same sites again and again. I'll admit I don't understand why! But here's my version.

    Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

    $webs = get-spsite [myurl] -Limit all | get-spweb -Limit all

    foreach ($web in $webs)
    {
      foreach ($lst in $web.lists)
      {
        foreach ($ctype in $lst.ContentTypes)
        {
          if ($ctype.Name -eq "myCTname")
          { $lst.DefaultViewUrl }
        }
      }
      $web.Dispose()
    }


    SharePoint Systems Officer, Capital Regional District, BC, Canada

    • Marked as answer by Elmo Watson Tuesday, July 23, 2013 12:45 PM
    Monday, July 22, 2013 10:37 PM