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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s