SharePoint Online: Get List Templates using PowerShell

Requirement: Get List Templates in SharePoint Online using PowerShell

You can get list templates in SharePoint Online from:
  • Site Settings >> "List templates" under "Web Designer Galleries"
get list templates sharepoint online powershell

PowerShell to Get List Templates in SharePoint Online 
If you need to get available list of templates in SharePoint Online, use this PowerShell script. It gets all SharePoint Online list templates from the given site.
#Load SharePoint Online 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"

#Custom Function to get all list templates from given site URL
Function Get-SPOListTemplates([String]$SiteURL)
{
    #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 All list templates
    $ListTemplates=$Ctx.Web.ListTemplates
    $Ctx.Load($ListTemplates)
    $Ctx.ExecuteQuery()

    #Get All Available list templates
        $ListTemplates | Select Name, baseType, ListTemplateTypeKind| Sort-Object Name | Format-Table -AutoSize
}

#Variable
$SiteURL="https://crescent.sharepoint.com"

#Call the function to get all list templates
Get-SPOListTemplates $SiteURL

PowerShell to Get All Custom List Templates in SharePoint Online:
#Custom Function to get all list templates from given site URL
Function Get-SPOCustomListTemplates([String]$SiteURL)
{
    #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 Custom list templates
    $ListTemplates=$Ctx.site.GetCustomListTemplates($Ctx.site.RootWeb)
    $Ctx.Load($ListTemplates)
    $Ctx.ExecuteQuery()

    #Get Custom list templates
    $ListTemplates | Select Name, baseType, ListTemplateTypeKind | Format-Table -AutoSize
}

#Variable
$SiteURL="https://crescent.sharepoint.com"

#Call the function to get all list templates
Get-SPOCustomListTemplates $SiteURL

Similarly, You can get a specific list template also
#Custom Function to get all list templates from given site URL
Function Get-SPOCustomListTemplate([String]$SiteURL, [string]$ListTemplateName)
{
    #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 Custom list templates
    $ListTemplates=$Ctx.site.GetCustomListTemplates($Ctx.site.RootWeb)
    $Ctx.Load($ListTemplates)
    $Ctx.ExecuteQuery()

    #Filter Specific List Template
    $ListTemplate = $ListTemplates | where { $_.Name -eq $ListTemplateName } 
    If($ListTemplate -ne $Null)
    {
        Return $ListTemplate
    }
    else
    {
        Write-host -f Yellow "List Template Not Found:"$ListTemplateName
    }
}

#Variable
$SiteURL="https://crescent.sharepoint.com"

#Call the function to get specific list template
$Template = Get-SPOCustomListTemplate $SiteURL -ListTemplateName "Quick Links Template"
SharePoint Online: Get List Templates using PowerShell SharePoint Online: Get List Templates using PowerShell Reviewed by Salaudeen Rajack on August 13, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.