【问题标题】:SharePoint Online Powershell CSOM create list from custom templateSharePoint Online Powershell CSOM 从自定义模板创建列表
【发布时间】:2016-09-06 05:25:16
【问题描述】:

全部,

我正在尝试使用自定义列表模板创建一个列表,其中包含使用 powershell 和 CSOM 的 SharePoint Online 内容。目前列表模板已加载到网站集中。如果我通过 UI,我可以使用包含内容的模板在网站上创建列表,而不会出现问题。如果我尝试通过 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()

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

【问题讨论】:

    标签: powershell sharepoint csom


    【解决方案1】:

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

    试试看这个:

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

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

    希望对您有所帮助。 亚历克斯

    【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2023-03-19
      • 2017-04-04
      • 2018-12-17
      • 2017-12-01
      • 2023-03-27
      • 1970-01-01
      • 2014-02-28
      • 1970-01-01
      • 2017-11-04
      相关资源
      最近更新 更多