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

Requirement: Delete a list template in SharePoint Online.

How to delete a list template SharePoint Online?

If you’re a SharePoint Online user, you know that list templates are a great way to save time when creating new SharePoint Online lists. But what if you want to delete a list template? In this blog post, we will discuss the steps necessary to delete a list template. We’ll also show you how to use PowerShell to delete a list template in SharePoint Online.

To remove a list template in SharePoint Online, do the following:

  1. Login to your SharePoint Online site collection (List templates are scoped at site collection level) >> Click on Settings >> Site Settings
  2. On the Site Settings page, click on “List Templates” under Web Designer Galleries (https://Tenant.sharepoint.com/sites/SiteURL/_catalogs/lt/Forms/AllItems.aspx)
  3. Select the list template to delete and click on “Delete Document” from the ribbon
  4. Confirm the prompt to delete the custom list template in SharePoint Online.
    sharepoint online delete list template

SharePoint Online: PowerShell to Delete List Template

You may need to delete a list template from time to time, So let’s see how to delete a list template in SharePoint Online using PowerShell:

#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"
    
#Variables for Processing
$SiteUrl = "https://crescent.sharepoint.com/sites/Projects"
$ListTemplateInternalName= "Project Tasks.stp"

#Get Credentials to connect
$Cred= Get-Credential
  
Try {    
    #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 Web
    $Web = $Ctx.Web
    $Ctx.Load($Web)
    $Ctx.ExecuteQuery()
    
    #Get the List Template
    $ListTemplateFile = $Web.GetFileByURL("_catalogs/lt/" + $ListTemplateInternalName)
    $Ctx.Load($ListTemplateFile)
    $Ctx.ExecuteQuery()

    If($ListTemplateFile -ne $Null)
    {
        $ListTemplateFile.Recycle()
        $Ctx.ExecuteQuery()
        Write-host -f Green "List Template Deleted Successfully!"
    }
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

PnP PowerShell to Delete a List Template in SharePoint Online:

To delete a list template, First, you need to connect to SharePoint Online using PowerShell. Next, you can use the Remove-PnPFile cmdlet to delete the list template. This cmdlet requires the -SiteRelativeURL parameter, which is the name of the list template you want to delete.

#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/IC"
$ListTemplateInternalName= "IC Documents.stp"

#Connect to the Site
Connect-PnPOnline -URL $SiteURL -Interactive

#Get the List Template
$TemplateFile = Get-PnPFolderItem -FolderSiteRelativeUrl "_catalogs/lt" -ItemName $ListTemplateInternalName

If ($TemplateFile -ne $null)
{   
    #Delete the List Template
    Remove-PnPFile -SiteRelativeUrl ("/_catalogs/lt/"+$ListTemplateInternalName) -Recycle -Force
    Write-host -f Green "List Template Deleted Successfully!"
}
Else
{
    Write-host -f Yellow "Template Not Found!"
}

In conclusion, You can delete a list template in SharePoint Online by following a few simple steps explained above. Also, it is possible to delete a list template in SharePoint Online using PowerShell. Keep in mind that you must have the site owner permission to delete a list template.

To create a new list template, refer: How to Create a List Template in SharePoint Online using PowerShell?

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *