SharePoint: Upload webpart to webpart gallery using Powershell

Following is the sample Powershell script which can be used to upload webpart file to SharePoint webpart gallery:

$siteCollectionUrl = "http://sp2010"
$listTitle = "Web Part Gallery"
$site =new-object Microsoft.SharePoint.SPSite($siteCollectionUrl)
$web = $site.OpenWeb()
$list = $web.Lists[$listTitle]
$folder = $list.RootFolder;
$file=Get-Item c:\HelloWorld_VisualWebPart1.webpart
$fileStream=([System.IO.FileInfo](Get-Item $file.FullName)).OpenRead()
$spFile=$folder.Files.Add($folder.Url + “/” + $file.Name, [System.IO.Stream]$fileStream, $true)
$fileStream.Close()
$web.Dispose()
$site.Dispose()
profile for Nadeem Yousuf at SharePoint Stack Exchange, Q&A for SharePoint enthusiasts

+