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

[玩转系统] SharePoint Online:使用 PowerShell 在列表视图中设置排序顺序、分组依据

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

SharePoint Online:使用 PowerShell 在列表视图中设置排序顺序、分组依据


要求: 使用 PowerShell 在 SharePoint Online 列表视图中设置排序顺序和分组依据。

如何设置 SharePoint Online 列表视图的排序顺序和分组依据设置?

在本文中,我们将逐步介绍如何使用 PowerShell 在 SharePoint Online 列表视图中设置排序顺序和分组依据字段。要在 SharePoint 列表视图中设置排序顺序或分组依据,请修改视图并选择排序和分组依据部分中的字段。

[玩转系统] SharePoint Online:使用 PowerShell 在列表视图中设置排序顺序、分组依据

PowerShell 在 SharePoint Online 的列表视图中设置排序顺序和分组依据

通过使用 PowerShell 自动执行此任务,我们可以节省时间并确保 SharePoint 网站之间的一致性。下面是为列表视图设置排序和分组依据选项的 PowerShell。


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Set parameter values
$SiteURL="https://Crescent.sharepoint.com/"
$ListName ="Documents"
$ViewName="All Documents"
 
Try {
    #Setup 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 view to update
    $View = $List.Views.GetByTitle($ViewName)
    $Ctx.ExecuteQuery()

    if($View -ne $NULL)  
    {
        #Define the CAML Query 
        $Query= "<OrderBy><FieldRef Name='LinkFilenameNoMenu' /></OrderBy>"

        #Update the View
        $View.ViewQuery = $Query
        $View.Update()
        $Ctx.ExecuteQuery()

        Write-host "View Updated Successfully!" -f Green
    }
    else
    {
        Write-host "View '$ViewName' Doesn't exist in the List!"  -f Yellow
    }
}
Catch {
    write-host -f Red "Error Updating List View!" $_.Exception.Message
}

同样,要设置 Group By 子句,请使用:


#Define the CAML Query 
$Query= "<GroupBy Collapse='TRUE' GroupLimit='30' ><FieldRef Name='Author' /></GroupBy>"

要设置 SharePoint 本地列表视图的排序顺序、分组依据设置,请参阅:使用 PowerShell 在 SharePoint 视图中设置排序顺序、筛选器、分组依据

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

取消回复欢迎 发表评论:

关灯