SharePoint Online: รับรายการตามชื่อเรื่องโดยใช้ PowerShell
ข้อกำหนด: PowerShell เพื่อรับรายการตามชื่อเรื่องใน SharePoint Online
SharePoint Online: PowerShell เพื่อรับรายการตามชื่อเรื่อง
ใน SharePoint Online นั้น PowerShell มอบวิธีที่มีประสิทธิภาพในการจัดการรายการและไลบรารี SharePoint งานทั่วไปอย่างหนึ่งเมื่อทำงานกับรายการ SharePoint ใน PowerShell คือการดึงข้อมูลรายการตามชื่อเรื่อง ในโพสต์บนบล็อกนี้ เราจะตรวจสอบวิธีรับรายการตามชื่อเรื่องใน SharePoint Online โดยใช้ PowerShell
ต่อไปนี้เป็นวิธีรับรายการตามชื่อ:
#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="Documents"
#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)
$Ctx.load($List)
$Ctx.ExecuteQuery()
Write-host "Total Number of List Items:"$List.ItemCount
PnP PowerShell เพื่อรับรายการตามชื่อ
หากคุณกำลังมองหาวิธีที่รวดเร็วในการรับรายการตามชื่อเรื่องใน SharePoint Online นี่คือ PnP PowerShell เพื่อรับรายการหรือไลบรารีจากไซต์ SharePoint Online:
#Set Parameters
$SiteURL="https://Crescent.sharepoint.com/sites/marketing"
$ListName= "Projects"
#Connect to SharePoint Online
Connect-PnPOnline -url $SiteURL -Interactive
#Get the List by its Title
$List = Get-PnPList -Identity $ListName
$list | Select-Object Title, Id, BaseTemplate
Write-host $List.ItemCount
ตามสคริปต์ที่ให้ไว้ในบทความนี้ คุณสามารถดึงข้อมูลรายการตามชื่อเรื่องและดำเนินการกับรายการนั้นโดยใช้ PowerShell ได้อย่างง่ายดาย