Archive for September, 2011

Create a list in all the sites using Powershell

September 20, 2011 3 comments

Here is way to create a list based on a custom template using Powershell. The script will go through each site and create the list and add them to the Quick Launch

$GetSites = Get-SPWebApplication | Get-SPSite | Get-SPWeb -Limit ALL
foreach($getsite in $GetSites)
$listTemplate = $getsite.Site.GetCustomListTemplates($getsite)
$getsite.Lists.Add("MyList","My List",$listTemplate["MyTemplate"])
$list = $getsite.Lists["MyList"]
$list.OnQuickLaunch = $true


Make sure that custom template is uploaded in the List Template Gallery. Check out this link  if you want to add a list template using powershell


Add List Template to all the site collections using Powershell

September 20, 2011 4 comments

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)


Categories: SharePoint