【发布时间】:2015-04-30 12:24:00
【问题描述】:
我有 VMWare 工作站和 PowerShell 的初学者知识。
我创建了一个脚本,该脚本使用vmrun 工具在我的本地计算机上成功启动了一个虚拟机。但是,如果我通过远程会话运行它,则不会发生任何事情。知道为什么吗?
Get-PSSession | Remove-PSSession
$VMHostMachine | New-PSSession
$rs = Get-PSSession # testing using localhost
Write-Debug ("Now starting VM on host: " + $VMHostMachine)
$script = {param($VMImagePath, $VMConsolePath);
$QuotedVMPath = "`"{0}`"" -f $VMImagePath
$Result = Start-Process -FilePath $VMConsolePath -ArgumentList "-T", "ws", "start", $QuotedVMPath -Wait -PassThru -NoNewWindow
}
Invoke-Command -Session $rs -ScriptBlock $script -ArgumentList $vmConfig.VMImagePathOnHost, $vmConfig.VMRunUtiltyPath
如果我删除会话参数,Invoke-Command 可以工作:
Invoke-Command -ScriptBlock $script -ArgumentList $vmConfig.VMImagePathOnHost, $vmConfig.VMRunUtiltyPath
我有一个类似的脚本,它通过 PSSession 成功恢复到我的本地主机上的快照,那么为什么启动 VM 会给我带来麻烦?
【问题讨论】:
标签: powershell virtual-machine powershell-remoting vmware-workstation vmrun