0

I have added two Content Types to a List some of the Fields exist in both content types so I have got duplicate fields. The field which is added by the new Content Type is empty.

Now I want to iterate through all items and copy data from fields associated with the old content type to the fields which are associated with the new Content Type.

How Can I find out which field is associated to which content type using PowerShell?

2 Answers 2

1

This powershell script will show the name of all content types that contains a field by its name.

$site = Get-SPSite http://YourSiteURL
$web = $site.RootWeb

$columnName = "Your_Site_Column_Name"
$guid = $web.fields[$columnName].id 

$contentTypes = $web.AvailableContentTypes
for ($x=0; $x -lt $contentTypes.Count; $x++) 
{
  for ($y=0; $y -lt $contentTypes[$x].Fields.Count; $y++) 
  {
    if ($contentTypes[$x].Fields[$y].id -eq $guid)
    {
      Write-Host $contentTypes[$x].Name " contains column " $columnName
    }
  }
}
0

Here's another way to do the same as above.

$fieldName = <Internal Field Name>
$web = Get-SPWeb <Site URL>

$field = $web.Fields[$fieldName]
$web.AvailableContentTypes | where{$_.Fields | where{$_.ID -eq $field.ID}} | Select ID, Name, Group

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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