Skip to content

Instantly share code, notes, and snippets.

@aflyen
Last active November 12, 2019 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aflyen/da04a090cae03ae4db58589fe2246716 to your computer and use it in GitHub Desktop.
Save aflyen/da04a090cae03ae4db58589fe2246716 to your computer and use it in GitHub Desktop.
#region Configuration
$Url = "https://TENANTID.sharepoint.com" # URL of the site
$ListTemplateInternalName = "CorpMenu.stp" # Change this with your own list template
$ListName = "Menu" # Change this with the name of the list to be created
#endregion
#region Create list from template
Connect-PnPOnline -Url $Url
$Context = Get-PnPContext
$Web = $Context.Site.RootWeb
$ListTemplates = $Context.Site.GetCustomListTemplates($Web)
$Context.Load($Web)
$Context.Load($ListTemplates)
Execute-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)
Execute-PnPQuery
Disconnect-PnPOnline
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment