Quantcast
Channel: SharePoint Diary
Viewing all articles
Browse latest Browse all 1058

SharePoint Online: Delete Column from List using PowerShell

$
0
0
Requirement: SharePoint Online delete column from list.

How to remove a column from SharePoint Online List?
To delete a list column, follow these steps:

  • Go to List settings by going to List tab >> Under Settings group, click on 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 Delete button.
    sharepoint online list delete column
  • Confirm the deletion prompt by clicking OK.
This deletes sharepoint online list column.

PowerShell to delete column from 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"

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)
$Column.DeleteObject()
$Ctx.ExecuteQuery()

Write-host "Column '$ColumnName' deleted Successfully!" -ForegroundColor Green
}
Catch {
write-host -f Red "Error Deleting Column from List!" $_.Exception.Message
}

Viewing all articles
Browse latest Browse all 1058

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>