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

Requirement: Delete 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 be walking through 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:

  • Login to your SharePoint Online site collection (List templates are scoped at site collection level) >> Click on Settings >> Site Settings
  • On the Site Settings page, click on “List Templates” under Web Designer Galleries (https://Tenant.sharepoint.com/sites/SiteURL/_catalogs/lt/Forms/AllItems.aspx)
  • Select the list template to delete and click on “Delete Document” from the ribbon
  • 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:

#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!"
}

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

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published.