1 Reply Latest reply on Mar 30, 2011 8:24 PM by Joshua Skirde

    Unable to run powershell command from blpackage / nsh

    Joshua Skirde

      Hi all,

       

      I'm having some issues with running a powershell command from an nsh (or blpackage).

      When run interactively I get:

      C:\tmp>1.cmd

      C:\tmp>powershell .\test.ps1

      C:\tmp\Pluralsight.Crypto.dll

      System.Security.Cryptography.X509Certificates.X500DistinguishedName

      Start create context

       

      When run via NSH I get the following:

      au2004sd0441% nexec -i -e 1.cmd

      c:\tmp>powershell .\test.ps1
      C:\tmp\Pluralsight.Crypto.dll
      System.Security.Cryptography.X509Certificates.X500DistinguishedName
      Start create context
      Exception calling "Open" with "0" argument(s): "The system cannot find the file specified. (Exception from HRESULT: 0x80070002)"
      At C:\tmp\test.ps1:16 char:26
      +             $context.Open <<<< ()
          + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
          + FullyQualifiedErrorId : DotNetMethodException

      Exception calling "CreateSelfSignedCertificate" with "1" argument(s): "You must call CryptContext.Open first."
      At C:\tmp\test.ps1:17 char:64
      +             $certificate = $context.CreateSelfSignedCertificate <<<< ($properties)
          + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
          + FullyQualifiedErrorId : DotNetMethodException

      You cannot call a method on a null-valued expression.
      At C:\tmp\test.ps1:21 char:39
      +             $pfx = $certificate.Export <<<< ('Pfx')
          + CategoryInfo          : InvalidOperation: (Export:String) [], RuntimeException
          + FullyQualifiedErrorId : InvokeMethodOnNull

       

      I'm no expert but it looks liike this powershell command is invoking some sort of .NET code under the covers but there is no graphical interaction so I would expect it to work. The user is mapped as Administrator and we're running BBSA 8.0 (SP6).


      I've tried wrapping it in additional command scripts, running it using "Start /wait" and all my other usual tricks but I continue to see this exception. Any ideas on how I can invoke this and get the same result as interactive?

       

      Kind regards,

      Joshua