2

I want to delete a site column using PowerShell, which is associated with my custom content types that are defined in my SharePoint 2013 site collection.When I removed the content type association manually, its removed correctly, but the association was not removed completely on the sub sites scope.

1
  • You may to need to clarify - I assume you removed the site column from the content type at the root site level - are you saying this did not remove the column from the content type in sub sites?
    – James Love
    May 26, 2015 at 14:32

1 Answer 1

2

If you have a look at this link you'll find a way to identify all content types which contain your column. Key to remove a column from a content type is to delete the FieldLink:

$content.FieldLinks.Delete("YourField");
$content.Update($true);

Update($true) will propagate all changes to the list content types (if there are any).

In the end you'll have to execute the linked code for all subsites aswell, before you can delete the site column. Make sure $field.ListsFieldUsedIn() returns empty after all.

7
  • I did this.But I am able to see this column in sub site's site columns section. Forgot to tell that it's a Lookup column
    – samolpp2
    May 26, 2015 at 14:36
  • $ContentTypeName = "Contracts and Agreements" $FieldDisplayName = "Operating Location" $web = Get-SPWeb $rootUrl # remove Field from Content Type and any derived Content Types $contentType = $web.ContentTypes[ $ContentTypeName ] $contentType.FieldLinks.Delete( $web.Fields[ $FieldDisplayName ].Id ) $contentType.Update( $true ) Write-Host "deleted the content link successfully"
    – samolpp2
    May 26, 2015 at 14:37
  • Removing the column from the content type doesn't delete the column. So have you tried deleting the site column?
    – Andreas
    May 26, 2015 at 14:48
  • $BULists = @("CBM-SE","CBM-SW","Common") $msitee = Get-SPSite "srvr1:123/sites/LAQ" $allWebs = $msitee.AllWebs # $msitee.split('?') foreach($singleWeb in $allWebs) { foreach ($singleList in $BULists) { $mlist = $singleweb.Lists[$singleList] $field = $list.Fields[ $FieldDisplayName ] #$field.AllowDeletion #= $true $field.Sealed = $false $field.Delete( ) $mlist.Update( ) $singleWeb.Dispose( ) } }
    – samolpp2
    May 27, 2015 at 4:32
  • i have added the code for deleting the column from the lists also.But this doesn't seem to work
    – samolpp2
    May 27, 2015 at 4:32

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.