[英]How do I remotely start a VM on VMWare Workstation using Powershell?
I have VMWare Workstation and beginner's knowledge of PowerShell. 我有VMWare工作站和PowerShell的初学者知识。
I've created a script that successfully starts a VM on my local machine by using the vmrun
tool. 我创建了一个脚本,可以使用
vmrun
工具在本地计算机上成功启动VM。 However, if I run it through a remote session, nothing happens. 但是,如果我通过远程会话运行它,则不会发生任何事情。 Any idea why?
知道为什么吗?
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
works if I remove the session parameter: 如果删除会话参数,则
Invoke-Command
有效:
Invoke-Command -ScriptBlock $script -ArgumentList $vmConfig.VMImagePathOnHost, $vmConfig.VMRunUtiltyPath
I have a similar script that successfully reverts to a snapshot on my localhost through a PSSession, so why is starting a VM giving me trouble? 我有一个类似的脚本,可以通过PSSession成功还原到本地主机上的快照,为什么启动VM会给我带来麻烦?
Does it work if you "enter-pssession" and then try to invoke? 如果您“输入pssession”然后尝试调用,它是否有效?
I'm assuming it's "not working" for you here, because you invoke commands through PSSession where there are no visible desktops / gui-session, and you are expecting the VMWare workstation to appear? 我在这里假设它“不起作用”,因为您通过PSSession在没有可见的桌面/ gui-session的情况下调用命令,并且您期望VMWare工作站出现吗? The receiving end is a service.
接收端是服务。
You could check if the process is running VMWare with Get-Process. 您可以使用Get-Process检查进程是否正在运行VMWare。
To do what you want to achieve here you could take a look at PsExec, which allows to start applications into an active session. 要在这里完成您想实现的目标,您可以看一下PsExec,它可以将应用程序启动到活动会话中。
https://technet.microsoft.com/en-US/sysinternals/bb897553.aspx https://technet.microsoft.com/zh-CN/sysinternals/bb897553.aspx
Note the "-i" parameter on PSExec. 注意PSExec上的“ -i”参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.