kwizcom banner advertisement

How to Export a List Template in SharePoint Online using PowerShell?

Requirement: Export List Templates in SharePoint Online using PowerShell

List templates in SharePoint Online enables you to reuse any list with its fields, formulas, formatting, and optionally data in other site collections without re-creating the list again. List Templates should be downloaded and uploaded to another sites in order to create lists from it. Here is how to download a list template SharePoint Online.

How to Export a List Template in SharePoint Online?
To download a list template from SharePoint Online site, 
  • Click on Settings gear >> Site settings page >> Click on "List Templates" under Web Designer Galleries (List template gallery in SharePoint Online URL: https://yourdomain.sharepoint.com/_catalogs/lt/Forms/AllItems.aspx)
  • In the "List templates Gallery", Click on "Name" column link for the list template you want to download. 
    export list template sharepoint online
  • This triggers file download prompt, click Save to download the file.
    download list template sharepoint online
List Templates feature is scoped at site collection. So, will be available only at top level site settings!

PowerShell to Export List Template in SharePoint Online
Here is the PowerShell to download a list template 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"

#Function to download a list template from SharePoint Online using powershell
Function Download-SPOListTemplate
{
    param
    (
        [string]$SiteURL  = $(throw "Enter the Site URL!"),
        [string]$ListTemplateName = $(throw "Enter the List Template Name!"),
        [string]$ExportFile = $(throw "Enter the File Name to Export List Template!")
    )
    Try {
        #Get Credentials to connect
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
        
        #Get the "List Templates" Library
        $List= $Ctx.web.Lists.GetByTitle("List Template Gallery")
        $ListTemplates = $List.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()) 
        $Ctx.Load($ListTemplates)
        $Ctx.ExecuteQuery()

        #Filter and get given List Template
        $ListTemplate = $ListTemplates | where { $_["TemplateTitle"] -eq $ListTemplateName }

        If($ListTemplate -ne $Null)
        {
            #Get the File from the List item
            $Ctx.Load($ListTemplate.File)
            $Ctx.ExecuteQuery()

            #Download the list template
            $FileInfo = [Microsoft.SharePoint.Client.File]::OpenBinaryDirect($Ctx,$ListTemplate.File.ServerRelativeUrl)
            $WriteStream = [System.IO.File]::Open($ExportFile,[System.IO.FileMode]::Create)
            $FileInfo.Stream.CopyTo($WriteStream)
            $WriteStream.Close()

            write-host -f Green "List Template Downloaded to $ExportFile!" $_.Exception.Message
        }
        else
        {
            Write-host -f Yellow "List Template Not Found:"$ListTemplateName
        }
    }
    Catch {
        write-host -f Red "Error Downloading List Template!" $_.Exception.Message
    } 
}

#Variables
$SiteURL = "https://crescenttech.sharepoint.com/"
$ListTemplateName= "Projects Template"
$ExportFile = "C:\Temp\CrescentProject.stp"

#Call the function to Download the list template
Download-SPOListTemplate -SiteURL $SiteURL -ListTemplateName $ListTemplateName -ExportFile $ExportFile
This PowerShell script exports list template in SharePoint Online. To deploy a list template in SharePoint Online , use: How to upload a list template to SharePoint Online using PowerShell?
How to Export a List Template in SharePoint Online using PowerShell? How to Export a List Template in SharePoint Online using PowerShell? Reviewed by Salaudeen Rajack on January 30, 2019 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.