Task: Upload a custom list template to specific site collections in a web application. While upload a list template using from SharePoint web interface is simple, wanted to automate this process as its repeating for multiple site collections.
So, Here is the PowerShell script to upload custom list template to SharePoint site :
So, Here is the PowerShell script to upload custom list template to SharePoint site :
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
Function UploadListTemplate($WebURL, $TemplateFilePath)
{
#Get the Web
$web = Get-SPWeb $WebURL
#Get the List template Gallery Folder
$TemplateFolder = $web.GetFolder("List Template Gallery")
#Get the Files collection
$TemplateFileCollection = $TemplateFolder.Files
#Get the Template file from Local File system
$TemplateFile = Get-ChildItem $TemplateFilePath
#Open the File in Read mode and Add to Templates collection
$TemplateFileCollection.Add("_catalogs/lt/$($TemplateFile.Name)", $TemplateFile.OpenRead(), $true)
Write-Host "Done!Template has been uploaded!!"
}
#Call the function
UploadListTemplate "http://sharepoint.crescent.com" "D:\Templates\CustomTaskList.stp"