2012-07-19 43 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