【问题标题】:Create a Document Library from a Template using SharePoint Online PowerShell使用 SharePoint Online PowerShell 从模板创建文档库
【发布时间】:2018-12-17 20:04:16
【问题描述】:

如何使用 SharePoint Online PowerShell 从保存为模板的现有文档库创建新文档库?

我正在尝试以下方法:

New-PnPList -Title "Test" -Template DocLibTemplate.stp -Url Test

我在 CSOM PowerShell 上没有运气... PnP 似乎是最好的选择。

【问题讨论】:

    标签: powershell sharepoint-online


    【解决方案1】:

    以下 PowerShell 供您参考。

    $ListTemplateInternalName="DocLibTemplate.stp"
    $ListName ="PnpDocument"
    Connect-PnPOnline -Url https://xx.sharepoint.com/sites/lz -Credential (Get-credential)
    
    $Context = Get-PnPContext
    $Web = $Context.Site.RootWeb
    $ListTemplates = $Context.Site.GetCustomListTemplates($Web)
    $Context.Load($Web)
    $Context.Load($ListTemplates)
    Invoke-PnPQuery
    
    $ListTemplate = $ListTemplates | where { $_.InternalName -eq $ListTemplateInternalName }
    
    if ($ListTemplate -eq $null)
    {
        Throw [System.Exception] "Template not found"
    }
    
    $ListCreation = New-Object Microsoft.SharePoint.Client.ListCreationInformation
    $ListCreation.Title = $ListName
    $ListCreation.ListTemplate = $ListTemplate
    
    $Web.Lists.Add($ListCreation)
    Invoke-PnPQuery
    
    Disconnect-PnPOnline
    

    【讨论】:

    • 你的例子很不错!它帮助我自己工作,我将所有内容更改为纯粹使用 PowerShell CSOM,感谢您的帮助!
    猜你喜欢
    • 2016-09-06
    • 2017-11-04
    • 2011-11-28
    • 2018-03-01
    • 1970-01-01
    • 2023-03-19
    • 2021-08-22
    • 1970-01-01
    • 2017-09-25
    相关资源
    最近更新 更多