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

[玩转系统] SharePoint Online:使用 PowerShell 从列表视图中获取所有字段

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

SharePoint Online:使用 PowerShell 从列表视图中获取所有字段


要求:从 SharePoint Online 列表视图获取所有字段。

如何从 SharePoint Online 视图获取列?

从 SharePoint Online 列表视图检索所有字段可用于多种目的,例如分析列使用情况、管理字段或将数据导出到外部系统。本文将指导您完成从 SharePoint Online 列表视图获取所有字段的步骤。

要查看 SharePoint Online 列表视图中包含的所有列,请执行以下操作:

  1. 转至要从视图中获取其所有字段的列表。
  2. 单击视图中任意列旁边的小向下箭头 >> 选择列设置 >> 显示/隐藏列。视图中包含的所有字段都将在此部分中列出。

[玩转系统] SharePoint Online:使用 PowerShell 从列表视图中获取所有字段

您还可以使用: 编辑当前视图以获取特定列表视图中包含的字段。

SharePoint Online:PowerShell 从列表视图中获取所有字段

此 PowerShell 脚本从 SharePoint Online 中的给定列表视图获取所有字段:


#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"
   
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com/"
$ListName="Projects"
$ViewTitle ="All Items" 

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
 
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred
   
    #Get the List
    $List=$Ctx.Web.Lists.GetByTitle($ListName)
    
    #Get the List View
    $ListView = $List.views.GetByTitle($ViewTitle)
    $Ctx.load($ListView)
    $Ctx.executeQuery()

    #Get all fields from the list view
    $ViewFields= $ListView.ViewFields
    $Ctx.Load($ViewFields)
    $Ctx.ExecuteQuery()

    #Loop through all the fields of the view
    ForEach($ViewField in $ViewFields)
    {
        #Get the Field Name
        Write-Host $ViewField
    }    
}
Catch {
    write-host -f Red "Error Getting List View Fields!" $_.Exception.Message
}

PnP PowerShell 从 SharePoint Online 视图获取所有列

以下是从列表视图中获取所有字段的 PnP PowerShell:


#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/pmo"
$ListName = "Projects"
$ViewName = "Active Projects"

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Interactive

    #Get the View
    $View = Get-PnPView -List $ListName -Identity $ViewName -Includes ViewFields
    
    #Get all Fields from the view - Internal Name
    $View.ViewFields
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

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

取消回复欢迎 发表评论:

关灯