Delete duplicate fields in a sharepoint list based on internal name


I have a similar issue where a content and structure migration created duplicate fields and had to delete fields based on internal name

My code:

$web = Get-SPWeb https://myWeb
$list = $web.Lists["Technical"]
$field = $list.Fields |?{$_.InternalName -eq "InternalNameofthefield"}
$field.ReadOnlyField = $false
$field.AllowDeletion = $true
$field.Sealed = $false
#if I dont update prior I can't delete - on sharepoint 2010 so update command first.
$field.update()
$field.Delete()
$list.Update()
$web.Dispose()

 

Advertisement