SharePoint Online: Delete Column from List using PowerShell
Requirement: SharePoint Online delete column from a list.
How to remove a column from SharePoint Online List?
In this article, we will show you how to delete a column from a SharePoint list. Deleted columns are permanently removed and can’t be restored. Keep in mind that any data contained in the column will also be deleted. Let’s get started!
We can delete Columns from lists or libraries when they are no longer needed. To delete a list column, follow these steps:
- Go to List >> Click on Settings Gear and choose “List Settings” (In Classic experience: Go to List tab >> Under Settings group, click on the List Settings button in the ribbon).
- Under the List Settings page, in the Columns section, click on the column title you wish to delete.
- Scroll down and click on the Delete button.
- Confirm the deletion prompt by clicking OK.
This deletes SharePoint Online list column. The changes will take effect immediately, That’s all.
SharePoint Online List: How to Delete a Column in Modern Experience?
To delete a column in a modern list, do the following:
- Navigate to the list or library that you want to delete a column from.
- Click on the column header for that you want to delete >> Select Column settings >> Edit
- Click on “Delete” button at the bottom of the Edit Column pane.
SharePoint Online: Delete List Column using PowerShell
Here is the PowerShell to delete a column from a List in SharePoint Online:
#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"
#Variables for Processing
$SiteURL="https://crescent.sharepoint.com"
$ListName= "Projects"
$ColumnName="Project Code" #Display Name of the column
Try {
#Get Credentials to connect
$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)
#Get the Column to delete
$Column = $List.Fields.GetByTitle($ColumnName)
#sharepoint online delete list column powershell
$Column.DeleteObject()
$Ctx.ExecuteQuery()
Write-host "Column '$ColumnName' deleted Successfully!" -ForegroundColor Green
}
Catch {
write-host -f Red "Error Deleting Column from List!" $_.Exception.Message
}
PnP PowerShell to Remove a Column from SharePoint Online List:
Here is how to remove a column from a list using PnP PowerShell in SharePoint Online.
#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$ListName= "Team Projects"
$ColumnName= "ProjectStartDate" #Internal Name
#Get Credentials to connect
$Cred = Get-Credential
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
#sharepoint online powershell delete list column
Remove-PnPField -Identity $ColumnName -List $ListName -Force -ErrorAction Stop
Write-host "Column '$ColumnName' Removed from the List Successfully!" -f Green
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
Delete Button missing in Column Settings? Getting “Operation is not valid due to the current state of the object” Error when trying to delete the field using PowerShell? Attempts to set “Sealed” Property also failed? Well, For now, I don’t find any other ways to delete a sealed column other than hiding it from the list! How to hide a column from SharePoint Online List?
If you want to remove a site column from SharePoint Online, use: SharePoint Online: Delete Column using PowerShell
Anyway to delete a field from a list when it exceeded the 5000 threshold limit?
Wish there was some direction on how to delete multiple columns! This was great though – thank you
Just place them in an Array and use the Remove-PnPField. E.g.
Great Help! The only thing I found out for “sealed” columns is to add these additional lines to the Column Section and the Update Command:
#Get the Column to delete
$Column = $List.Fields.GetByTitle($ColumnName)
$Column.Hidden = $false
$Column.ReadOnlyField = $false
$Column.Sealed = $false
$Column.Update()
$Column.DeleteObject()
$Ctx.ExecuteQuery()
I’ve no luck setting the “Sealed” Property to $False. Tried even updating schema, but it didn’t work!
This is exactly what I have been searching for!