SharePoint Online: Belirli İçerik Türüne Göre Liste Öğesi Oluşturma


Gereksinim: SharePoint Online'da belirli içerik türüne sahip liste öğesi ekleyin.

SharePoint Online'da belirli bir içerik türüne ait Yeni Liste Öğesi Nasıl Eklenir?

Kişi listesi için özelleştirilmiş bir içerik türü olan "İş Bağlantıları"na sahip olduğumuzu ve verilen içerik türüne yeni bir öğe eklemek istediğimizi varsayalım. SharePoint Online'da belirli bir içerik türünde yeni bir liste öğesi oluşturmak için, o listenin "Yeni" menüsünden istediğiniz içerik türünü seçmeniz yeterlidir!

Benim durumumda, listedeki "Yeni" düğmesine tıklamak yerine "Yeni" öğe açılır menüsünden "İş Bağlantıları"nı seçtim.

Belirli bir içerik türünde bir liste öğesi oluşturmak için PowerShell:

SharePoint Online'da belirli bir içerik türünde bir liste öğesi oluşturmak için bir PowerShell betiği mi arıyorsunuz? Bu blog gönderisi, SharePoint Online listesinde "İş Kişileri" içerik türünün bir liste öğesini oluşturmak için PowerShell'i nasıl kullanacağınızı gösterecektir.


#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
} 

Belirli bir İçerik Türünden Liste Öğesi Eklemek için 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"} 

İlgili makaleler