Hello @Liam ,
SharePoint Online: Remove a Field from List Content Type using PowerShell
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Function Remove-ColumnFromListContentType()
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $ListName,
[Parameter(Mandatory=$true)] [string] $ContentTypeName,
[Parameter(Mandatory=$true)] [string] $ColumnName
)
Try {
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get the List
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
#Get the content type from list
$ContentTypeColl = $List.ContentTypes
$Ctx.Load($ContentTypeColl)
$Ctx.ExecuteQuery()
#Check if the content type exists in the list
$ContentType = $ContentTypeColl | Where {$_.Name -eq $ContentTypeName}
If($ContentType -eq $Null)
{
Write-host "Content Type '$ContentTypeName' doesn't exists in '$ListName'" -f Yellow
Return
}
#Get the column to delete from content type
$ContentTypeFieldColl = $ContentType.Fields
$Ctx.Load($ContentTypeFieldColl)
$Ctx.ExecuteQuery()
$Field = $ContentTypeFieldColl | Where {$_.Title -eq $ColumnName }
if($Field -eq $null)
{
Write-host "Column '$ColumnName' Doesn't exists in Content Type '$ContentTypeName'" -f Yellow
}
else
{
#Get the field link from content type
$FieldLinkColl = $ContentType.FieldLinks
$Ctx.Load($FieldLinkColl)
#Remove field from content type
$FieldLink = $FieldLinkColl.GetById($Field.Id)
$FieldLink.DeleteObject()
$ContentType.Update($false)
$Ctx.ExecuteQuery()
Write-host "Column '$ColumnName' Deleted from '$ContentTypeName' Successfully!" -ForegroundColor Green
}
}
Catch {
write-host -f Red "Error Deleting Column from Content Type!" $_.Exception.Message
}
}
#Set parameter values
$SiteURL="https://test.sharepoint.com/sites/echo"
$ListName="doc"
$ContentTypeName="Project"
#Display Name of the Field
$ColumnName="Description"
#Call the function
Remove-ColumnFromListContentType -SiteURL $SiteURL -ListName $ListName -ContentTypeName $ContentTypeName -ColumnName $ColumnName
Note:
Get-PnPProperty -ClientObject $testlist -property "ContentTypes"
AND
"$doctype = Get-PnPContentType -Identity Document"
The displayed “Description” is only the Description property of the Content Type, not looks the Description column/filed of the Content Type.
Thanks,
Echo Du
===========
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.