SharePoint Online: How to Create a List Template using PowerShell?

Requirement: Create List Template in SharePoint Online

How to Create List Template in SharePoint Online?
List templates in SharePoint Online provides re-usability without having to recreate every single field and other settings in SharePoint list. E.g. you may created a custom list (say: Projects) in a SharePoint site collection with all relevant columns, and then you may need that list structure in other site collections, without recreating the list on every single site. To create list template in SharePoint Online, follow these steps:
  • Go to your SharePoint Online List >> Navigate to List settings
  • Click on "Save list as Template" under Permissions and Management group.
    create list template in sharepoint online
  • Provide the file name and template name
    sharepoint online save list as template powershell
  • Choose the appropriate option for "include content" and Click OK to create list template in SharePoint Online.

SharePoint Online: Save List as Template using PowerShell
Lets use PowerShell to save list as template in SharePoint Online
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Set parameter values
$SiteURL="https://crescenttech.sharepoint.com/"
$ListName="Projects"

#Configure Save list as template parameters
$FileName="Projects Template"
$TemplateName="Projects Template"
$Description ="List Template for Projects"
$IncludeData = $False

Try{
    #Get Credentials to connect
    $Cred= Get-Credential
  
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
    #Get the List
    $List = $Ctx.Web.lists.GetByTitle($ListName)
    $List.SaveAsTemplate($FileName, $TemplateName, $Description, $IncludeData)
    $Ctx.ExecuteQuery()

    Write-Host -f Green "List Saved as Template!"
}
Catch {
        write-host -f Red "Error Saving List as template!" $_.Exception.Message
} 
This PowerShell script creates a list template in SharePoint Online.

SharePoint Online Save List as Template URL - https://YourDomain.SharePoint.com/_layouts/15/savetmpl.aspx?List={LIST-GUID}

Save list as Template is not visible in SharePoint Online? Here is the fix: SharePoint Online: Save List as Template Missing?
SharePoint Online: How to Create a List Template using PowerShell? SharePoint Online: How to Create a List Template using PowerShell? Reviewed by Salaudeen Rajack on September 18, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.