Last active
November 12, 2019 01:08
-
-
Save aflyen/da04a090cae03ae4db58589fe2246716 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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