我有一个带有PowerCLI命令的powershell脚本文件,比如Connect-VIServer等。我将库引用添加到VMWare PowerCLI之后能够在PowerGUI中运行脚本文件,但我不知道如何通过SoapUI运行它。我猜它也不适用于常规的Powershell CLI。有没有办法让这项工作?这是错误,如果它有帮助:
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 :(得分:4)
尝试在脚本的开头调用它:
Add-PSSnapin "VMware.VimAutomation.Core" | Out-Null
答案 1 :(得分:1)
您无法在Powershell主机外执行PowerCLI命令。
要将管理单元添加到任何Powershell主机,请使用Tomas提到的命令:
Add-PSSnapin VMware.VimAutomation.Core