繁体   English   中英

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

[英]SharePoint Online Powershell CSOM create list from custom template

所有,

我正在尝试使用自定义列表模板创建列表,该模板包含使用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()

我无法弄清楚缺少什么,任何帮助将不胜感激。

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

试试看:

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

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

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

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

...      
$lci.Title = "Some List"
$lci.TemplateFeatureId = $template.FeatureId    
$lci.TemplateType = $template.ListTemplateTypeKind    
$lci.DocumentTemplateType = $template.ListTemplateTypeKind   
$lci.ListTemplate = $template   
...    

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM