views:

29

answers:

1

Hello all,

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

+2  A: 

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.

Goyuix