Saturday, January 25, 2014

How to Upload a List Template using PowerShell

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 :

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 "" "D:\Templates\CustomTaskList.stp"

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...