0

I need to find out the field or site column which are not associated with any content types in my SP 2013 site collections using PowerShell

  • what do you need that for? why don't you just look for the fields that ARE associated with content types? – Gwny May 29 '15 at 6:31
  • and what have you tried so far? – Vadim Gremyachev May 29 '15 at 7:58
4

Here is the powershell script for listing out all the site columns which are not associated with any web content types in a given web

   $web = Get-SPWeb "http://YourWebURL"
    write-host -foregroundcolor white "Fields or site columns which are not associated with any content types: "
    foreach ($field in $web.Fields){

    if ($field.UsedInWebContentTypes -eq $false){
         write-host -foregroundcolor Yellow $field.Title
    }
      }
      $web.Dispose()

Here is the powershell script for listing out all the site columns which are not associated with any list content types in a given web

      $web = Get-SPWeb "http://YourWebURL/"
write-host -foregroundcolor white "Fields or site columns which are not used in any list content types: "

foreach ($field in $web.Fields){
    $flag = $false;
  foreach ($list in $web.Lists){
    if ($list.Fields.ContainsField($field.Title) -eq $true){
           $flag = $true;
           break;
    }

    }
      if ($flag -eq $false){
          write-host -foregroundcolor Yellow $field.Title
  }
  }
  $web.Dispose()
  • Thanks for the reply, Can I get the same in usedinListcontenttypes also? – SaMolPP May 29 '15 at 9:07
  • I edited my answer above, check that an let me know if you have any questions. – Naveen May 29 '15 at 9:51
  • Thanks for the reply, your time and code.If I explain my scenario a little bit,we have CTH,MMS, and took backup and restore of these content DBs and ported in production.But when I ran the timer jobs in PROD. few strange things happened.Few columns which were part of the content type in CTH, were getting duplicated in list content types of few collections and all columns were available in other set of site collections.If mycolumnA is the column is displayed in subscriberSite1 the same column is duplicated as mycolumnA0. But mycolumnA0 is not associated with any of my custom CTs. – SaMolPP May 30 '15 at 5:31
  • so, I am stuck at finding these columns which are in lists having not associated with any of my custom content types.How to find out these columns which are at doc.lib level and not associated with any of the content types.I already tried your code but unfortunately it does not give me actual results.Let me modify it again and revert. CT-Content Type CTH-Content Type Hub. MMS-Managed Metadata Services – SaMolPP May 30 '15 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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