VirtualBox + Powershell? VirtualBox + Powershell? powershell powershell

VirtualBox + Powershell?


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/