在 SharePoint 中使用 PowerShell 从视图中删除字段
如何从 SharePoint 视图中删除列?
您想要从 SharePoint 视图中删除列吗?在本指南中,我们将向您展示如何使用 Web 界面和 PowerShell 从列表视图中删除字段。
- 浏览到 SharePoint 中的列表或库 >> 单击功能区中的“列表”或“库”选项卡。
- 单击“管理视图”组下的“修改视图”按钮。
在“编辑视图”页面中,取消选中要从特定视图中删除的列。
- 单击“确定”保存。
如果您想使用 PowerShell 以编程方式从视图中删除字段,请执行以下操作:
SharePoint 使用 PowerShell 从视图中删除列:
那么,如果视图中有列,您就不再需要了吗?以下是用于从视图中删除列的 PowerShell。
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Function: sharepoint powershell delete field from view
Function Remove-FieldFromView([Microsoft.SharePoint.SPList]$List, [String]$ViewName, [string]$FieldInternalName)
{
#Get the view
$View = $List.Views[$ViewName]
If($view -eq $Null) {write-host "View doesn't exists!" -f Red; return}
#Check if view has the specific field already!
if($view.ViewFields.ToStringCollection().Contains($FieldInternalName))
{
#Remove field from view:
$View.ViewFields.delete($FieldInternalName)
$View.Update()
write-host "Field Removed from the View!" -f Green
}
else
{
write-host "Field Doesn't Exists in the view!" -f Red
}
}
#configuration parameters
$WebURL="https://portal.crescent.com/projects/"
$ListName="Project Milestones"
$ViewName="All Items"
$FieldName="ProjectDescription"
#Get the Web and List
$Web= Get-SPWeb $WebURL
$List = $web.Lists.TryGetList($ListName)
#Call the function to remove column from view
Remove-FieldFromView $List $ViewName $FieldName
此 PowerShell 脚本从给定视图中删除给定字段。
使用 PowerShell 从 SharePoint 的默认视图中删除列:
要从默认视图中删除该列,只需更改该行即可。
$View = $List.Views[$ViewName]
到 :
$View: List.DefaultView
