Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

The following code just gives me the URL of the site collection. However I need to be able to determine which list is using this content type. Do I need iterate through splistitemcollection?

$site = Get-SPSite("http://portal.brisk.tea/sites/GreenTea");
foreach ($web in $site.AllWebs) 
{    
  $ctype = $web.ContentTypes["NewTeaSample"]
  $usages = [Microsoft.Sharepoint.SPContentTypeUsage]::GetUsages($ctype)    
  foreach ($usage in $usages)
  {
       Write-Host $usage.Url
  }
} 
share|improve this question
    
I added $ctuse.IsUrlToList method and it returns false. Does this mean the content type in question is not hooked any list for the given site collection? –  Rosie O'Donnell Nov 15 '11 at 19:21
    
I am trying to delete a content type and it's telling me it's been in use but the scripts tell me otherwise. –  Rosie O'Donnell Nov 15 '11 at 19:28
    
how many results do you get? –  Ashish Patel Nov 15 '11 at 20:32
add comment

2 Answers

up vote 1 down vote accepted
  1. Make sure there aren't any sub content type that is using or inheriting from this content type. if yes, delete the child CT that inherits from this and then delete the CT in question.

-- if above does not help then you may want to try these steps ---

  1. Clean your recycle bin as there may be list or library RB that is/r using this content type.
  2. Then try to delete the CT.
share|improve this answer
    
Perfect. You step 1 helped like magic. There was a child CT that was inheriting from this CT. I delete the child CT, then Parent CT became delete friendly. Thanks Mary. –  Rosie O'Donnell Nov 15 '11 at 21:35
add comment

If the content type was used in a list, the $usage.Url will be same as SPList's RootFolder.ServerRelativeUrl and $usage.IsUrlToList will be true. Hope this helps you.

share|improve this answer
    
But CT is not in use in any library but code returns the url /sites/GreenTea and Isurltolist is false. I am trying to delete the CT and getting ct in use error. –  Rosie O'Donnell Nov 15 '11 at 19:40
    
This makes sense because /sites/GreenTea appears to be a site (root web) and not a list. –  Ashish Patel Nov 15 '11 at 19:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.