I want to add a new developed WebPart to a SharePoint site with PowerShell.

How it is possible to add the WebPart reference from my WebPart to the PowerShell script?

$web = Get-SPWeb $urlWeb

$webpartmanager=$web.GetLimitedWebPartManager($urlWebWP,  [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

$webpart = new-object  ReferenceToMyWebPartProblem

$webpartmanager.AddWebPart($webpart, $webpartzone, $index);
link|improve this question

71% accept rate
feedback

1 Answer

up vote 2 down vote accepted

Here is a link to a page that describes the process for the out of the box SharePoint webparts. If you want to include your own webpart, you need to add a reference to your assembly in powershell. The following line adds a reference to one of my custom webparts into powershell.

 [System.Reflection.Assembly]::Load("rossri.NavigationControl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a60d1a662835ad70")

Once the reference is added, I can then create a new object of the type of my custom webpart. For fun I changed the title and then added it using the webpartmanager object.

$webpart = New-Object rossri.NavigationControl.UserListViewPart.UserListViewPart
$webpart.Title = "NewPart from Powershell"
$webpartmanager.AddWebPart($webpart, "Left", "0")

I checked the page and it was added to the zone I defined.

link|improve this answer
Thank you so much! Great comment! – LaPhi Aug 30 '11 at 6:56
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.