我有 VMWare 工作站和 PowerShell 的初学者知识。
我创建了一个脚本,可以使用该vmrun
工具在本地计算机上成功启动 VM。但是,如果我通过远程会话运行它,则不会发生任何事情。知道为什么吗?
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 会给我带来麻烦呢?