Cannot Delete Site Columns from Document Library or Content Type

Recently I ran into an issue where one of the SharePoint users added an existing site column called “Active” into one of the document libraries and was not able to remove it. This is a strange behavior from SharePoint and is because some “AllowDeletion” field property is set to true by default. Anyway, I was able to delete the filed using the following PowerShell script.

$web = Get-SPWeb https://siteurl/
$list = $web.Lists["Shared Documents"]
$field = $list.Fields["Active"]
$field.AllowDeletion = “true”
$field.Sealed = “false”
$field.Delete()
$list.Update()
$web.Dispose()


In this case, the column was added only to the Document Library; not to the site content type. If these types of columns were added to site content types, you could use the following script.

$web = Get-SPWeb http://siteurl/
$ct = $web.ContentTypes["Document"]
$spFieldLink = New-Object Microsoft.SharePoint.SPFieldLink($web.Fields["Active"])
$ct.FieldLinks.Delete($spFieldLink.Id)
$ct.Update()
$web.Dispose()

Thanks to Brendan Well’s blog which saved me a lot of time.

Advertisements