Home > SharePoint > Add List Template to all the site collections using Powershell

Add List Template to all the site collections using Powershell


Here is a way to upload a list template to all the site collections. Instead of going to all the site collections and upload the template manually .. use the script below to add them using Powershell

$GetSiteCollections = Get-SPWebApplication | Get-SPSite -Limit ALL
## Add the List Template to the all the Site Collections
foreach($GetSiteCollection in $GetSiteCollections)
{
$web = $GetSiteCollection.OpenWeb();
$spfolder = $web.getfolder("_catalogs\lt")
$spfileCollection = $spfolder.Files
$file = Get-Item c:\Temp\MyListTemplate.stp
spfileCollection.Add"MyListTemplate.stp", $file.OpenRead(),$true)
}

Thanks

Advertisements
Categories: SharePoint
  1. WeekendCoder
    November 2, 2011 at 2:29 am

    If I had a site called mysite.com/sitecollections/ where I had 10 site collections numbered 1 – 10, where my first site would be mysite.com/sitecolletions/1/ and so on and so forth, would I list the variable $SPSite = “mysite.com/sitecollections/” before line 1 of your code?

    • November 2, 2011 at 6:20 pm

      To iterate through site collections underneath site collections do this

      $GetSites = Get-SPSite “http://mysite.com/sitecollections/*” -Limit ALL

      Thanks

      Hemant

  2. September 5, 2013 at 5:25 am

    I tried to run this but kept getting validation errors.. I figured out your missing a $ and ()
    Try this instead….
    $GetSiteCollections = Get-SPSite -Limit ALL
    ## Add the List Template to the all the Site Collections
    foreach($GetSiteCollection in $GetSiteCollections)
    {
    $web = $GetSiteCollection.OpenWeb();
    $spfolder = $web.getfolder(“_catalogs\lt”)
    $spfileCollection = $spfolder.Files
    $file = Get-Item c:\Templates\MyListTemplate.stp
    $spfileCollection.Add(“MyListTemplate.stp”, $file.OpenRead(), $true)
    }

  1. September 20, 2011 at 11:20 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: