0

This is the code I use:

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
$web = Get-SPWeb "Myshareointsite/Projects/Test"
$list = $web.Lists["Risks"]
$ContentType = $list.ContentTypes["Item"]
$ColumnName = "Comment"
    if($ContentType -ne $null)
    {
 Write-host $ContentType.Fields
        if($ContentType.Fields.ContainsField($ColumnName))
        {

        $ContentType.FieldLinks.Delete($ColumnName)
        $ContentType.Update()
        Write-Host "Field removed from the Content Type!" -ForegroundColor Green
        }
        else
        {
        Write-Host "Field Doesn't Exists in the Content Type!" -ForegroundColor Red
        }
    }
    else
    {
    Write-Host "Content type not found!" -ForegroundColor Red 
    }

at the end of the execution, I get the message: Field removed from the content type but when I check in the column, the field is still there any idea of what I'm doing wrong?

Thank for your help

0

Try Using your code in below format:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$SiteURL="http://intranet.crescent.com/"
$ListName="Change Request"
$ColumnName="Activity Status"

#Get Internal Name of the columns
$web = Get-SPWeb $SiteURL

#Get the list
$list = $web.Lists.TryGetList($ListName)

if($List -ne $null)
{
    #Get the column
    $column = $list.Fields[$ColumnName]

    if($column -ne $null)
    {
        #Reset column properties to allow delete
        $column.Hidden = $false
        $column.ReadOnlyField = $false
        $column.AllowDeletion = $true
        $column.Update()

        #Delete the column from list
        $list.Fields.Delete($column)
        write-host "Column has been deleted!" -f Green
    }
    else
     {
        write-host "Specified column name not found!" -ForegroundColor Red
     }
}

Reference:

How to Remove a Column from SharePoint List using PowerShell?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.