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

[玩转系统] SharePoint Online:PowerShell 更新列表视图

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

SharePoint Online:PowerShell 更新列表视图


要求:使用 PowerShell 更新 SharePoint Online 中的列表视图。

[玩转系统] SharePoint Online:PowerShell 更新列表视图

SharePoint Online:PowerShell 更新列表视图

这篇博文将向您展示如何使用 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"

#Function to Update List View in SharePoint Online
Function Update-SPOListView($SiteURL, $ListName, $ViewName, $ViewQuery)
{
    Try { 
        #Get Credentials to connect
        $Cred= Get-Credential
 
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
        #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)  
        {
            #Update the View Query
            $View.ViewQuery = $ViewQuery
            $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:" $_.Exception.Message
    }
}

#Set parameter values
$SiteURL = "https://Crescent.sharepoint.com"
$ListName ="Projects"
$ViewName="Active Projects"
$ViewQuery ="<Where><Eq><FieldRef Name = 'ProjectStatus' /><Value Type ='Choice'>Active</Value></Eq></Where>"

#Call the function
Update-SPOListView -SiteURL $SiteURL -ListName $ListName -ViewName $ViewName -ViewQuery $ViewQuery 

使用 PnP PowerShell 更新 SharePoint Online 中的视图

让我们使用 PnP PowerShell 通过设置过滤器来更新列表视图:


#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$ListName ="Projects"
$ViewName="Active Projects"
$ViewQuery ="<Where><Eq><FieldRef Name = 'ProjectStatus' /><Value Type ='Choice'>Active</Value></Eq></Where>"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the Client Context
$Context = Get-PnPContext
 
#Get the List View
$View = Get-PnPView -Identity $ViewName -List $ListName
 
#Update the view Query
$View.ViewQuery = $ViewQuery
$View.Update() 
$Context.ExecuteQuery() 

PnP PowerShell 在 SharePoint Online 中将视图类型设置为“平铺”

以下是在 SharePoint Online 中更新视图设置的另一个示例。


#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$ListName = "Branding"
$ViewName= "All Documents" 

#Connect to the Site
Connect-PnPOnline -URL $SiteURL -Interactive

#Set View Properties
Set-PnPView -List $ListName -Identity $ViewName -Values @{"ViewType2" = "TILES"} 

可以通过 PowerShell 更新的其他属性有哪些?

  1. 聚合
  2. 聚合状态
  3. 列宽
  4. 内容类型ID
  5. 自定义格式化程序
  6. 默认视图
  7. 内容类型的默认视图
  8. 编辑修改
  9. 格式
  10. 包含根文件夹
  11. JSLink
  12. 列表视图Xml
  13. 方法
  14. 移动默认视图
  15. 移动视图
  16. 新文档模板
  17. 对象版本
  18. 分页
  19. 行限制
  20. 范围
  21. 表格视图
  22. 标签
  23. 标题
  24. 工具栏
  25. 查看数据
  26. 查看连接
  27. 查看投影字段
  28. 查看查询
  29. 可视化信息

相关文章:

  • SharePoint Online:使用 PowerShell 在列表视图中添加/删除字段
  • SharePoint Online:使用 PowerShell 在列表视图中设置排序顺序、分组依据

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

取消回复欢迎 发表评论:

关灯