当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 在 SharePoint 中使用 PowerShell 从视图中删除字段

作者:精品下载站 日期:2024-12-14 14:07:25 浏览:16 分类:玩电脑

在 SharePoint 中使用 PowerShell 从视图中删除字段


如何从 SharePoint 视图中删除列?

您想要从 SharePoint 视图中删除列吗?在本指南中,我们将向您展示如何使用 Web 界面和 PowerShell 从列表视图中删除字段。

  • 浏览到 SharePoint 中的列表或库 >> 单击功能区中的“列表”或“库”选项卡。
  • 单击“管理视图”组下的“修改视图”按钮。
  • 在“编辑视图”页面中,取消选中要从特定视图中删除的列。

    [玩转系统] 在 SharePoint 中使用 PowerShell 从视图中删除字段

  • 单击“确定”保存。

如果您想使用 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 

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯