ค้นหาเว็บไซต์

SharePoint Online: รับฟิลด์ทั้งหมดจากมุมมองรายการโดยใช้ PowerShell


ความต้องการ: รับฟิลด์ทั้งหมดจากมุมมองรายการ SharePoint Online

วิธีรับคอลัมน์จากมุมมอง SharePoint Online

การดึงเขตข้อมูลทั้งหมดจากมุมมองรายการ SharePoint Online อาจมีประโยชน์สำหรับวัตถุประสงค์ต่างๆ เช่น การวิเคราะห์การใช้งานคอลัมน์ การจัดการเขตข้อมูล หรือการส่งออกข้อมูลไปยังระบบภายนอก บทความนี้จะแนะนำคุณตลอดขั้นตอนในการรับเขตข้อมูลทั้งหมดจากมุมมองรายการ SharePoint Online

เมื่อต้องการดูคอลัมน์ทั้งหมดที่รวมอยู่ในมุมมองรายการ SharePoint Online ให้ทำดังต่อไปนี้:

  1. ไปที่รายการที่คุณต้องการรับฟิลด์ทั้งหมดจากมุมมอง
  2. คลิกลูกศรลงเล็กๆ ถัดจากคอลัมน์ใดๆ ในมุมมอง >> เลือกการตั้งค่าคอลัมน์ >> แสดง/ซ่อนคอลัมน์ ฟิลด์ทั้งหมดที่รวมอยู่ในมุมมองจะแสดงรายการในส่วนนี้

คุณยังสามารถใช้: แก้ไขมุมมองปัจจุบันเพื่อให้ฟิลด์รวมอยู่ในมุมมองรายการเฉพาะ

SharePoint Online: PowerShell เพื่อรับฟิลด์ทั้งหมดจากมุมมองรายการ

สคริปต์ PowerShell นี้รับฟิลด์ทั้งหมดจากมุมมองรายการที่กำหนดใน SharePoint Online:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\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
}

บทความที่เกี่ยวข้อง