SharePoint Online:使用 PowerShell 从列表中删除列
要求:从 SharePoint Online 列表中删除列。
如何从 SharePoint Online 列表中删除列?
在 SharePoint Online 中,您可以在不再需要时从列表中删除列。在本文中,我们将向您展示如何从 SharePoint 列表中删除列。已删除的列将被永久删除且无法恢复。请记住,该列中的所有数据也将被删除。让我们开始吧!
当不再需要列时,我们可以从列表或库中删除它们。要删除列表列,请执行以下步骤:
- 导航到要删除的列所在的列表
单击“设置齿轮”并选择“列表设置”(在经典体验中:转到“列表”选项卡 >> 在“设置”组下,单击功能区中的“列表设置”按钮)。
- 在“列表设置”页面下的“列”部分中,单击要删除的列标题。
-
向下滚动并单击删除按钮。
- 单击“确定”确认删除提示。
这将删除 SharePoint Online 列表列。更改将立即生效。您可以通过刷新列表页面并检查该列是否不再列出来验证它是否已被删除。您还可以返回列表设置并检查列列表以确认该列已被删除。
请注意,当您删除 SharePoint 中的列时,该列中保存的所有数据也会被删除!我们无法从回收站恢复该列数据!
SharePoint Online 列表:如何在现代体验中删除列?
要删除新式列表中的列,请执行以下操作:
SharePoint Online:使用 PowerShell 删除列表列
以下是用于从 SharePoint Online 列表中删除列的 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"
#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 从 SharePoint Online 列表中删除列:
下面介绍了如何使用 SharePoint Online 中的 PnP PowerShell cmdlet Remove-PnPField 从列表中删除列。
#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
}
列设置中是否缺少删除按钮?尝试使用 PowerShell 删除字段时出现“由于对象的当前状态,操作无效”错误?尝试设置“封印”属性也失败了?好吧,目前,除了将密封列从列表中隐藏之外,我没有找到任何其他方法来删除它!如何从 SharePoint Online 列表中隐藏列?
如果要从 SharePoint Online 中删除网站列,请使用:SharePoint Online:使用 PowerShell 删除列



