简体   繁体   English

如何使用Powershell在VMWare Workstation上远程启动VM?

[英]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.

相关问题 如何使用 powershell 从我的办公室桌面远程重启 Azure VM 上的 windows 服务? - How do I restart a windows service on an Azure VM remotely from my office desktop using powershell? 如何使用 SSH 远程解锁 Windows 工作站? - How can I remotely unlock a Windows workstation using SSH? 如何使用PowerShell检查任务中当前未运行的特定VMware VM? - How to check particular VMware VM is not currently running in the task using PowerShell? 如何使用Powershell远程安装“重要” Windows Update? - How do I install “Important” Windows Updates remotely using Powershell? 无法使用Powershell远程连接到Azure VM - Unable to connect to Azure VM remotely using powershell 如何在PowerShell中启动远程处理 - How to start remotely process in PowerShell 如何使用PowerShell脚本远程启动/停止IIS 6.0 / 7.0? - How To start/stop IIS 6.0/7.0 remotely using PowerShell Scripts? 如何使用Powershell远程以提升的权限启动批处理脚本 - How can I start a batch script with elevated permissions remotely with powershell 如何使用Powershell获取具有特定数据存储使用空间25%以上的vmware vm列表? - How to get vmware vm list which has more than 25% of used space of the particular datastore using powershell? 如何通过Powershell启动VM - How to start a VM through Powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM