3

Delete please - not possible. Going to repost question in different section.

closed as unclear what you're asking by Waqas Sarwar MVP Jun 24 '17 at 3:08

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • What's inside the webpart? – ranbo Jun 14 '17 at 14:17
  • It is a handshake webpart, so it has all the settings I need. For some reason I cannot import it so I am trying to copy it from a site that I will use to house the web part. – The Inexperienced Gamer Jun 14 '17 at 14:21
0

You're really close.

Get rid of the foreach loop but keep the bit about instantiating the web part instance, then call AddWebPart on your web part manager, passing in an instance of your new-object HSWebServiceRender.

  • I tried that but now I am getting the following error: New-Object : Exception calling ".ctor" with "0" argument(s): "Object reference not set to an instance of an object." At line:21 char:48 + $webPart2 = new-object <<<< HandshakeWebParts.HSWebServiceRender + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand Even this does not work: – The Inexperienced Gamer Jun 19 '17 at 16:46
  • even if I try this it does not work and throws the same error: even if I just try: [Reflection.Assembly]::LoadWithPartialName("HandshakeWebParts") $webPart2 = new-object HandshakeWebParts.HSWebServiceRender – The Inexperienced Gamer Jun 19 '17 at 16:50
  • There's a problem with the constructor of the HSWebServiceRender class. It could be that it just won't run when not in a web site context (you can fake this, though). You might be able to get more info by running that script to throw that error again, then looking at $error[0].Exception.StackTrace in the powershell console. If that gets you the MethodInvocationException then do $error[0].Exception.InnerException.StackTrace – James Love Jun 19 '17 at 20:18
  • Here's an article on Faking an SPContext in PowerShell - pholpar.wordpress.com/2013/07/15/… – James Love Jun 19 '17 at 20:19

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