Thursday, September 26, 2013

How To Delete a Site Column from all Document Libraries using Powershell

Use below Powershell script to Delete a Site Column

$web = Get-SPWeb http:/mywebapp/
$list = $web.Lists["Shared Documents"]
$field = $list.Fields["Column to be deleted"]
$field.AllowDeletion = “true”
$field.Sealed = “false”

or use below script to delete the site column from all Document Libraries

Get-SPWeb -site   http://spsite -Limit All | foreach {
$doclibtype = [Microsoft.SharePoint.SPBaseType]::DocumentLibrary
$doclibs = $_.GetListsOfType($doclibtype)
for ($i=0; $i -lt $doclibs.Count; $i++)
$doclib = $doclibs[$i]
$fieldtype = [Microsoft.SharePoint.SPFieldType]::Choice
$doclib.Fields.Delete(“Column to be deleted”)
#$view = $doclib.Defaultview
#$view.viewFields.Add("Column name")
Write-Host "Field Deleted"

No comments:

Post a Comment