VirtualBox +电源外壳?
我已经创建了一个虚拟机。现在我尝试使用 Powershell 启动它。我在互联网上搜索了有关如何执行此操作的任何详细信息。这是我找到的唯一代码...
#----------------------
$vBox = New-Object -ComObject VirtualBox.VirtualBox
$vBox | Get-Member *
$vBox.Machines
$vBox.CreateMachine()
#----------------------
(来源:http://www.ravichaganti.com /blog/?p=1275)
事实上,我在 virtualbox.org 上找不到有关 com 对象的任何文档。我非常精通 powershell,我花了一些时间探索 com 对象...
$vBox | gm
我尝试了我能想到的所有方法,但只收到错误。 我的问题是如何使用 Powershell 启动我的虚拟机
谢谢
I have created a virtual machine. Now I am trying to launch it using Powershell. I have searched all over the internet for any details on how to do that. This is the only code i found...
#----------------------
$vBox = New-Object -ComObject VirtualBox.VirtualBox
$vBox | Get-Member *
$vBox.Machines
$vBox.CreateMachine()
#----------------------
(Source: http://www.ravichaganti.com/blog/?p=1275)
In fact, I cant find any documentation on the com objects on virtualbox.org. I am fiarly proficent with powershell, I spent some time exploring the com object with...
$vBox | gm
I tried every thing I could think of but only receive errors.
My question is how do I launch my VM using Powershell
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与其使用 COM 对象,为什么不直接使用 VBoxManage 命令行界面呢?
与您的问题相关的命令是:
VBoxManage 可执行文件位于安装目录中,默认情况下为 C:\Program Files\Oralce\VirtualBox(至少从版本 3.2.8 开始)。
使用 COM API,VirtualBox.OpenSession 方法似乎是唯一的方法你需要使用,但我似乎无法让 PowerShell 强制 ISession 变量匹配方法签名并调用该方法。也许通过一些聪明的反思或者其他什么可以让它发挥作用。
Rather than use the COM objects - why not just use the VBoxManage command line interface?
The relevant commands to your question are:
The VBoxManage executable is found in the installation directory, which by default will be C:\Program Files\Oralce\VirtualBox (as of version 3.2.8 at least).
Using the COM API, it would appear that the VirtualBox.OpenSession method is the one you need to use, but I can't seem to get PowerShell to coerce the ISession variable to match the method signature and invoke the method. Maybe through some clever reflection or something it could be made to work.
以下链接包含一篇有关在 PowerShell 中使用 VirtualBox 的文章,并包含一个方便的模块,其中包含一些不错的 PowerShell cmdlet。
虽然您可以使用命令行,但命令很长,它不是交互式的,并且您无法轻松解析结果(例如机器列表等)。
这仅适用于 PowerShell。
链接中的模块包含一个包装器对象,因此您不必担心 COM 对象或任何内容的处置。
这是链接:
http://jdhisolutions.com/blog/scripting/1502/managing -virtualbox-with-powershell/
The following link contains an article about using VirtualBox in PowerShell and contains a handy module which contains some nice PowerShell cmdlets.
While you can use the command-line, the command is long, it is not interactive and you cannt easily parse the results (eg. list of machines etc).
This just works with PowerShell.
The module in the link contains a wrapper object so you don't have to worry about disposing of the COM object or anything.
Here is the link:
http://jdhitsolutions.com/blog/scripting/1502/managing-virtualbox-with-powershell/