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

SharePoint Online: สร้างรายการตามประเภทเนื้อหาที่ระบุ


ความต้องการ: เพิ่มรายการที่มีประเภทเนื้อหาเฉพาะใน SharePoint Online

จะเพิ่มรายการใหม่ของประเภทเนื้อหาเฉพาะใน SharePoint Online ได้อย่างไร

สมมติว่าเรามีประเภทเนื้อหาแบบกำหนดเอง “ที่ติดต่อทางธุรกิจ” สำหรับรายชื่อผู้ติดต่อ และต้องการเพิ่มรายการใหม่ของประเภทเนื้อหาที่กำหนด เมื่อต้องการสร้างรายการใหม่ของประเภทเนื้อหาเฉพาะใน SharePoint Online เพียงเลือกประเภทเนื้อหาที่ต้องการจากเมนู "ใหม่" ของรายการนั้น!

ในกรณีของฉัน ฉันได้เลือก "ข้อมูลติดต่อทางธุรกิจ" จากรายการแบบเลื่อนลง "ใหม่" แทนที่จะคลิกปุ่ม "ใหม่" ของรายการ

PowerShell เพื่อสร้างรายการประเภทเนื้อหาเฉพาะ:

คุณกำลังมองหาสคริปต์ PowerShell เพื่อสร้างรายการของชนิดเนื้อหาเฉพาะใน SharePoint Online หรือไม่? โพสต์ในบล็อกนี้จะแสดงวิธีใช้ 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="Contacts"
$ContentTypeName="Business Contacts"

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)
    $Ctx.Load($List)
    $Ctx.ExecuteQuery()

    #Get the content type from list
    $ContentTypeColl = $List.ContentTypes
    $Ctx.Load($ContentTypeColl)
    $Ctx.ExecuteQuery()
 
    #Get the content type
    $CType = $ContentTypeColl | Where {$_.Name -eq $ContentTypeName}
    If($CType -ne $Null)
    {
        #Create a List Item of specific content type
        $ListItemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
        $ListItem = $List.AddItem($ListItemInfo)
        #Set List Item Fields - Internal Names
        $ListItem["Title"] = "Ruta"
        $ListItem["FirstName"] = "Graciela"
        $ListItem["Company"] = "Buckley Miller & Wright"
        $ListItem["WorkPhone"] = "440-780-8425"
        $ListItem["Email"] = "gruta@cox.net"

        #Set Content type for the Item
        $ListItem["ContentTypeId"] = $CType.ID
        $ListItem.Update()
        $Ctx.ExecuteQuery()

        Write-host "New Item Added to the List!" -ForegroundColor Green
    }
    else
    {
        Write-host "Content Type Doesn't exist in the List!" -ForegroundColor Yellow
    }
}
Catch {
    write-host -f Red "Error Adding Items to List!" $_.Exception.Message
} 

PnP PowerShell เพื่อเพิ่มรายการจากประเภทเนื้อหาเฉพาะ


#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Retail"
$ContentTypeName = "Business Contacts"
$ListName = "Contacts"
 
#Connect to SharePoint Online Site
Connect-PnPOnline -Url $SiteURL -Interactive

#Create List Item based on specific content type
Add-PnPListItem -List $ListName -ContentType $ContentTypeName -Values @{"Title" = "Ruta" ; "FirstName" ="Graciela"} 

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