0

I have created the site column named as "tags" as a taxonomy type of field.Also added into the content type. If i delete and re-add the content type , it's not working. it's throwing error 'A duplicate field name "Kac23234.." was found'. how to delete the note field using power shell script. anyone suggest the better idea to resolve this issue.

1 Answer 1

0

Try below the Code, it will delete the taxonomy field with hidden note field.

function CleanUpSiteColumns($siteColl, $group){

$siteColumns = $siteColl.RootWeb.Fields | Where-Object{$_.Group -eq $group}
foreach($siteColumn in $siteColumns)
{
    $noteFieldId = $null

    Write-Host "Deleting " $siteColumn.Title

    #If it is a taxonomy field, get the id of the hidden note field
    if($siteColumn.GetType().Name -eq "TaxonomyField")
    {
        #TaxtField holds the Id of the hidden notes field            
        $noteFieldId = $siteColumn.TextField
    }

    #Delete the Site Column
    $siteColumn.Delete()
    #Write-Host $noteFieldId


    #If notes field is there, find it and delete it as well
    if($noteFieldId -ne $null)
    {
        $noteFields = $siteColl.RootWeb.Fields | Where-Object {$_.Id -eq $noteFieldId }
        if($noteFields -ne $null)
        {
            #Find the column
            foreach($noteField in $noteFields)
            {
                Write-Host "Deleting " $noteField.Title
                $noteField.Delete()
            }
        }
    }
}
}
  $siteCollection = Get-SPSite siteURL
  CleanUpSiteColumns $siteCollection "Taxonomy Columns"
2
  • $noteFieldId = $siteColumn.TextField - returns like 00000000-0000-...... So the note field or references cannot be deleted. is any other way to improve this?
    – PGP
    Feb 15, 2018 at 11:24
  • Ya , you're right. My issue was note field is not mapped to taxonomy field in sire column.
    – PGP
    Feb 17, 2018 at 18:26

Your Answer

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

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