3

I have a powershell script file with PowerCLI commands like Connect-VIServer etc. I am able to run the script file in PowerGUI after I added the library references to VMWare PowerCLI but I don't know how to run it through SoapUI. I'm guessing it won't work with the regular Powershell CLI either. Is there any way to make this work? Here's the error, if it helps:

The term 'Connect-VIServer' is not recognized as the name of a cmdlet, function
, script file, or operable program. Check the spelling of the name, or if a pat
h was included, verify that the path is correct and try again.
At Test.ps1:10 char:23
+ $vm = Connect-VIServer <<<<  -Server $vcenterIP -User $vcenterUser -Password 
$vcenterPW
    + CategoryInfo          : ObjectNotFound: (Connect-VIServer:String) [], Co 
   mmandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
dhishkaow
  • 81
  • 1
  • 2
  • 8
  • I realize I can do this if I can run the script from the normal windows Command prompt. In my Groovy script in SoapUI I execute this command "powershell Test.ps1". It might work for me if I use something like "powercli Test.ps1". Unfortunately that doesn't work. Is there any such magic command? – dhishkaow Jul 19 '12 at 19:21

2 Answers2

4

try calling this in the beginning of the script:

Add-PSSnapin "VMware.VimAutomation.Core" | Out-Null
Tomas Panik
  • 4,337
  • 2
  • 22
  • 31
  • Added that to the Groovy script in soapUI and got a bunch of errors: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script2.groovy: 1: expecting EOF, found 'VMware.VimAutomation.Core" – dhishkaow Jul 19 '12 at 19:07
  • Also tried adding it to the Powershell script after figuring out that it was a script and not meant for Groovy :D. Didn't help :( – dhishkaow Jul 19 '12 at 19:11
1

You cannot execute PowerCLI commands outside of a Powershell host.

To add the snap-in to any Powershell host, use the command Tomas mentioned:

Add-PSSnapin VMware.VimAutomation.Core
JakeRobinson
  • 298
  • 3
  • 14