开发者

VirtualBox + 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


Rather than use the COM objects - why not just use the VBoxManage command line interface?

The relevant commands to your question are:

VBoxManage createvm     --name <name>
                        [--ostype <ostype>]
                        [--register]
                        [--basefolder <path> | --settingsfile <path>]
                        [--uuid <uuid>]

VBoxManage startvm      <uuid>|<name>
                        [--type gui|sdl|vrdp|headless]

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.


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜