2012-07-19 67 views
2

我有PowerCLI命令像Connect-VIServer等PowerShell脚本文件我能够在PowerGUI中运行脚本文件后,我添加到VMWare PowerCLI库引用,但我不知道如何通过SoapUI运行它。我猜测它不适用于常规的Powershell CLI。有什么办法可以做到这一点?这里的错误,如果它可以帮助:使用SoapUI运行VMWare powerCLI命令

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 
+0

我知道我能做到这一点,如果从正常的Windows命令提示符下,我可以运行该脚本。在我的SoapUI的Groovy脚本中,我执行这个命令“powershell Test.ps1”。如果我使用诸如“powercli Test.ps1”之类的东西,它可能对我有用。不幸的是,这是行不通的。有没有这样的魔法命令? – dhishkaow 2012-07-19 19:21:38

回答

4

尝试在脚本的开头调用此:

Add-PSSnapin "VMware.VimAutomation.Core" | Out-Null
+0

添加到soapUI中的Groovy脚本中,并得到了一堆错误:org.codehaus.groovy.control.MultipleCompilationErrorsException:启动失败:Script2.groovy:1:期待EOF,发现'VMware.VimAutomation.Core“ – dhishkaow 2012-07-19 19:07:24

+0

也尝试添加它发现后,它的Powershell脚本,它是一个脚本,并不意味着Groovy:D没有帮助:( – dhishkaow 2012-07-19 19:11:35

1

您不能执行的PowerCLI命令PowerShell的主机之外。

要将管理单元添加到任何PowerShell主机,使用托马斯提到的命令:

Add-PSSnapin VMware.VimAutomation.Core