Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 612
user464818 Avatar asked May 15 '26 21:05

user464818


1 Answers

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.

like image 143
Goyuix Avatar answered May 19 '26 04:05

Goyuix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!