Daves Occasional SharePoint Thoughts.....

Thinking about SharePoint....and some other dev stuff that floats me boat.

Powershell script to locate content type useage.

Powershell script to locate content type useage.

  • Comments 2

This is a simple script I knocked up to locate which SPWebs and SPLists where using a particular content type. Just update the first two lines of the script to include your web application name and the content type you are looking for. The script will then search all site collections looking for the named content type. I intend at some point to update this to include which list items (or documents in a document library) are using which content type as well.

 

$targetCT = "Summary Task"
$targetWebApp = "http://intranet.contoso.com"

$webapp = Get-SPWebApplication $targetWebApp
$sites = $webapp.Sites

foreach ($site in $sites)
{
  foreach ($web in $site.AllWebs)
  {
    foreach ($ct in $web.ContentTypes)
    {
       if($ct.Name -eq $targetCT)
       {
          Write-Host $targetCT is defined as a content type in $web.Url
       }

    }

    foreach ($list in $web.Lists)
    {
       foreach ($listct in $list.ContentTypes)
       {
         if($listct.Name -eq $targetCT)
         {
            Write-Host $targetCT is defined in list $list in $web.Url
         }

       }

    }
    Write-Host

  }
}

Page 1 of 1 (2 items)
Leave a Comment
  • Please add 7 and 5 and type the answer here:
  • Post