SharePoint Online Powershell CSOM从自定义模板创建列表

时间:2016-05-11 02:15:15

标签: powershell sharepoint csom

所有

我正在尝试使用自定义列表模板创建列表,该模板包含使用powershell和CSOM的SharePoint Online内容。现在的列表模板已加载到网站集中。如果我浏览用户界面,我可以使用包含内容而无问题的模板在网站上创建列表。如果我尝试通过powershell执行此操作,则会创建列表但不包含列和/或内容。

$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()

我无法弄清楚缺少什么,我们将非常感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

我认为您必须将字段与内容类型(CT)相关联,然后将此CT添加到您的列表中。

试试看:

http://www.sharepointfire.com/2016/01/create-new-content-type-sharepoint-online-powershell/

在上一步中,他创建了他在创作中使用的列(字段): $ columns =“BlogNumber”,“BlogText”,“BlogUser”

希望它会对你有所帮助。 亚历

答案 1 :(得分:0)

我认为您必须在更新之前添加列表模板。它对我有用

...      
$lci.Title = "Some List"
$lci.TemplateFeatureId = $template.FeatureId    
$lci.TemplateType = $template.ListTemplateTypeKind    
$lci.DocumentTemplateType = $template.ListTemplateTypeKind   
$lci.ListTemplate = $template   
...    
相关问题