SharePoint Online: สร้างรายการจากเทมเพลตแบบกำหนดเองโดยใช้ PowerShell
ความต้องการ: สร้างรายการจากเทมเพลตรายการแบบกำหนดเองโดยใช้ PowerShell ใน SharePoint Online
SharePoint Online: วิธีสร้างรายการจากเทมเพลต
เทมเพลตรายการใน SharePoint Online ประหยัดเวลาได้มากด้วยการนำรายการหรือไลบรารีเอกสารที่มีอยู่กลับมาใช้ใหม่ ซึ่งประกอบด้วยคอลัมน์ทั้งหมดและข้อมูลจากรายการ (ไม่บังคับ) คุณสามารถสร้างสำเนาจำนวนเท่าใดก็ได้จากเทมเพลตรายการ
สมมติว่าคุณมีเทมเพลตรายการที่มีอยู่ในไซต์ ต่อไปนี้เป็นวิธีสร้างรายการจากเทมเพลต SharePoint Online:
- เข้าสู่ระบบไซต์ SharePoint Online ของคุณ >> คลิกที่ไอคอนรูปเฟืองการตั้งค่า และคลิก "เพิ่มแอป"
คุณสามารถใช้การแบ่งหน้าเพื่อค้นหาเทมเพลตรายการของคุณหรือช่องค้นหา "ค้นหาแอป" เพื่อเลือกเทมเพลตรายการของคุณ
- ตั้งชื่อให้กับรายการใหม่ของคุณแล้วคลิก "ตกลง" ซึ่งจะสร้างรายการใหม่จากเทมเพลตใน SharePoint Online
- คุณจะเห็นรายการใหม่ที่สร้างขึ้นด้วยสคีมารายการเดียวกันและข้อมูล หากคุณเลือก "รวมเนื้อหา" เมื่อสร้างเทมเพลตรายการตั้งแต่แรก มาดู SharePoint Online PowerShell เพื่อสร้างรายการจากเทมเพลตกัน
SharePoint Online: สร้างรายการจากเทมเพลตโดยใช้ PowerShell
รายการคือองค์ประกอบหลักที่ SharePoint ใช้เพื่อจัดเก็บข้อมูล ลองใช้ PowerShell ใน SharePoint Online เพื่อสร้างรายการจากเทมเพลต
#Load SharePoint Online 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 Variables
$SiteURL="https://crescent.sharepoint.com"
$ListTemplateName = "Quick Links Template"
$ListName="Quick Links V2"
#Get 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 All Lists
$Lists = $Ctx.Web.Lists
$Ctx.Load($Lists)
$Ctx.ExecuteQuery()
#Get the Custom list template
$ListTemplates=$Ctx.site.GetCustomListTemplates($Ctx.site.RootWeb)
$Ctx.Load($ListTemplates)
$Ctx.ExecuteQuery()
#Filter Specific List Template
$ListTemplate = $ListTemplates | where { $_.Name -eq $ListTemplateName }
If($ListTemplate -ne $Null)
{
#Check if the given List exists
$List = $Lists | where {$_.Title -eq $ListName}
If($List -eq $Null)
{
#Create new list from custom list template
$ListCreation = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$ListCreation.Title = $ListName
$ListCreation.ListTemplate = $ListTemplate
$List = $Lists.Add($ListCreation)
$Ctx.ExecuteQuery()
Write-host -f Green "List Created from Custom List Template Successfully!"
}
else
{
Write-host -f Yellow "List '$($ListName)' Already Exists!"
}
}
else
{
Write-host -f Yellow "List Template '$($ListTemplateName)' Not Found!"
}
วิธีการเดียวกันนี้ใช้กับการสร้างไลบรารีเอกสารจากเทมเพลตแบบกำหนดเอง
SharePoint Online: PnP PowerShell เพื่อสร้างรายการจากเทมเพลต
รายการเป็นองค์ประกอบหลักสำหรับการจัดเก็บข้อมูลใน SharePoint นี่คือ PnP PowerShell สำหรับสร้างรายการจากเทมเพลต:
#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$ListName = "Migation Tasks"
$ListTemplateName ="Project Tasks"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Get the Custom List Template
$Ctx = Get-PnPContext
$Web = Get-PnPWeb
$RootWeb = $Ctx.Site.RootWeb
$ListTemplates = $Ctx.Site.GetCustomListTemplates($RootWeb)
$Ctx.Load($RootWeb)
$Ctx.Load($ListTemplates)
Invoke-PnPQuery
$ListTemplate = $ListTemplates | where {$_.Name -eq $ListTemplateName}
#sharepoint online powershell create list from template
$ListCreation = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$ListCreation.Title = $ListName
$ListCreation.ListTemplate = $ListTemplate
$Web.Lists.Add($ListCreation)
Invoke-PnPQuery
ทำตามขั้นตอนที่อธิบายไว้ในบทความนี้ คุณสามารถสร้างรายการใหม่จากเทมเพลตที่สร้างไว้ล่วงหน้า ปรับแต่งรายการให้ตรงกับความต้องการเฉพาะของคุณ และเริ่มเพิ่มข้อมูลลงในรายการ
