I found this article which does a very good job explaining how to add built in web parts (like the content editor webpart). Unfortunately when I tried to add my own I couldn't get it to work. I have the webpart already installed on my sharepoint instance, I have checked the GAC and confirmed that the assembly for my webpart is there, but when I try to run this line:

$webpart = New-Object HighlightsTicker.HighlightsTickerPart.HighlightsTickerPart

I get the error:

New-Object : Cannot find type [HighlightsTicker.HighlightsTickerPart.HighlightsTickerPart]: make sure the assembly containing this type is loaded. At C:\Users\amiessler\AppData\Local\Temp\3\8c524086-dcea-4250-a4b9-0722c51e3d8f.ps1:5 char:22 + $webpart = New-Object <<<< HighlightsTicker.HighlightsTickerPart.HighlightsTickerPart + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

This is what the code for my HightlightsTickerPart.cs looks like namespace/classname wise:

namespace HighlightsTicker.HighlightsTickerPart
{
    [ToolboxItemAttribute(false)]
    public class HighlightsTickerPart : WebPart
    {

Do I need to do something differently to get this to work with a custom webpart?

link|improve this question

feedback

1 Answer

up vote 2 down vote accepted

You may need to load the assembly containing the web part in your PowerShell Session, if you have not done so already. See below:

http://www.dougfinke.com/blog/index.php/2010/08/29/how-to-load-net-assemblies-in-a-powershell-session/

I think LoadWithPartialName is the way to go in this case.

link|improve this answer
I ended up using Load Looks like LoadWithPartialName has been deprecated. Ended up looking like this: [reflection.assembly]::Load("HighlightsTicker, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ccdee482b415afe7") – Abe Miessler Dec 15 '11 at 16:29
feedback

Your Answer

 
or
required, but never shown

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