Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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);
share|improve this question
add comment

1 Answer 1

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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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