While deleting a list column I see an error: Cannot change hidden attribute for this field.
I have changed the Hidden property to False. But still no luck. It keeps on throwing the error.
The script I use to change to Hidden property and then try to delete the column is below:
$Web = Get-SPWeb <url to web>
$List = $web.Lists["Library"]
$SectionField = $List.Fields.GetField("Section")
Write-Host "CanToggleHidden: " $SectionField.CanToggleHidden
$Type = $SectionField.GetType()
$MethodInfo = $Type.GetMethod("SetFieldBoolValue", [System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Instance)
$MethodInfo.Invoke($SectionField, @("CanToggleHidden", $true))
Write-Host "CanToggleHidden: " $SectionField.CanToggleHidden
$SectionField.Hidden = $false
$SectionField.ReadOnlyField = $false
$SectionField.Sealed = $false
$SectionField.Update()
$Web = Get-SPWeb <url to web>
$List = $web.Lists["Library"]
$SectionField = $List.Fields.GetField("Section")
$SectionField.Delete()
The PowerShell console throws the same error:
Can someone suggest what is wrong with the Field or what other things I need to check?