Reputation: 481
How do I create a new document library from an existing document library saved as template using SharePoint Online PowerShell?
I was trying the following:
New-PnPList -Title "Test" -Template DocLibTemplate.stp -Url Test
I had no luck on CSOM PowerShell... PnP seemd to be the best option available.
Upvotes: 0
Views: 1844
Reputation: 4228
The following PowerShell for your reference.
$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
Upvotes: 1