【发布时间】:2017-12-10 12:03:08
【问题描述】:
我有一个 PowerShell 2.0 脚本,用于在 Windows 主机环境中使用 vmrun 克隆目标 vmware 工作站来宾。 克隆虚拟机的代码正确执行。
我现在正在尝试扩展此脚本以自动化更多过程,例如,检查虚拟机是否正在运行,vmrun list,并停止虚拟机,vmrun stop [pathToVMXfile] 如果正在运行。
在 Windows 命令提示符下,当我运行 vmrun list 时,它会返回以下内容:
正在运行的虚拟机总数:2
D:\[路径]\[名称].vmx
E:\[路径]\[名称].vmx
当我在 PowerShell 中尝试以下操作时,没有任何返回。这是我到目前为止所尝试的。我期待一个数组返回我从命令提示符运行时看到的值。
$vmwareRun = "C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe"
#Original test, also tried with single quotes and no quotes,
#also tried quoting the -filePath
Start-Process $vmwareRun -ArgumentList "list"
#This gives a handle to the process but no return value
$myProcess = Start-Process $vmwareRun -ArgumentList "list" -PassThru
#$t is empty
Start-Process $vmwareRun -ArgumentList "list" -OutVariable $t
#$t is empty, clone command requires the -T ws parameters
Start-Process $vmwareRun -ArgumentList "-T ws list" -OutVariable $t
#RedirectStandardOutput creates a file with the expected output, $t is empty
Start-Process -FilePath "$vmwareRun" -ArgumentList $argList -OutVariable $t -RedirectStandardError "C:\testError.log" -RedirectStandardOutput C:\testOut.log"
无论我尝试什么,我都没有得到任何输出。我错过了什么? 注意:Vmrun 命令行文档可在此处找到:“https://www.vmware.com/support/developer/vix-api/vix112_vmrun_command.pdf”
谢谢。
【问题讨论】:
-
如果您使用(在 PowerShell 提示符下,在 vmrun 目录中):
.\vmrun.exe /?或.\vmrun.exe --help是否列出了参数选项? -
我可以在 cmd 提示符下。我无法从 Powershell 进行验证,因为 cmd 窗口会快速显示并消失
标签: powershell vmware vmrun