All,
I am trying to create a list using a custom list template that includes content for SharePoint Online using powershell and CSOM. The list template for now is already loaded into the site collection. If I go through the UI, I can create the list on a site using the template including content without issue. If I try to do it through powershell, the list gets created but without the columns and or contents.
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
$clientContext.Credentials = $credentials
if (!$clientContext.ServerObjectIsNull.Value)
{
Write-Host "Connected to SharePoint Online site: '$Url'" -ForegroundColor Green
}
$web = $clientContext.Web
$templates = $clientContext.Site.GetCustomListTemplates($web)
$clientContext.Load($templates)
$clientContext.ExecuteQuery()
$template = $templates | Where-Object{ $_.Name -eq "SomeTemplate" }
$lci = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$lci.Title = "Some List"
$lci.TemplateFeatureId = $template.FeatureId
$lci.TemplateType = $template.ListTemplateTypeKind
$lci.DocumentTemplateType = $template.ListTemplateTypeKind
$lists = $clientContext.Web.Lists;
$clientContext.Load($lists);
$clientContext.ExecuteQuery();
$list = $lists.Add($lci)
$list.Update()
$clientContext.ExecuteQuery()
I can't figure out what is missing, any help would be much appreciated.
I think you have to associate Fields to Content Type (CT) and then add this CT to your List.
Try look at this:
http://www.sharepointfire.com/2016/01/create-new-content-type-sharepoint-online-powershell/
In previous step he created Columns(Fields) which he used in creation: $columns = "BlogNumber", "BlogText", "BlogUser"
Hope it will help you. Alex
I Think you have to add the list template before update. It works for me
...
$lci.Title = "Some List"
$lci.TemplateFeatureId = $template.FeatureId
$lci.TemplateType = $template.ListTemplateTypeKind
$lci.DocumentTemplateType = $template.ListTemplateTypeKind
$lci.ListTemplate = $template
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.