PowerShell, Scripting, VirtualBox, Virtualization
comments 7

Managing VirtualBox using PowerShell – Part 1: Introduction to COM objects

The VirtualBox is a nice piece of work by the people at Sun and the community around it. I started using this especially because it lets me run x64 OS for my SharePoint 2010 demo virtual machines. VMWare Workstation can also do this but I found VirtualBox to be an easier one to use. I love VirtualBox’s seamless mode too.   

VirtualBox supports COM API and also has a command-line tool called vboxmanage.exe. However, automating using the command-line requires lot of text parsing, unnecessary coding and that is not fun. So, I started experimenting a bit with VirtualBox COM API and found that it is rather easy to program that in PowerShell. I wrote a few scripts to complement my existing OS VM / SharePoint deployment automation. I will start sharing those scripts here. The end goal is to generate a PowerShell wrapper that can be used even from a remote machine to manage VirtualBox virtual machines.   

VirtualBox COM Objects   

When you install VirtualBox on a Windows computer, you will find three COM objects in the system as shown here.   

VirtualBox COM Objects

VirtualBox COM Objects

 We will look at each of these objects — one at a time though. Today, we will look at VirtualBox.VirtualBox object and some of it’s properties and methods. To instantiate this COM object we will use New-Object cmdlet.   

In the first line, we instantiate the COM object and in the second line we get a list of all methods and properties of this COM object.  

VirtualBox.VirtualBox Members

VirtualBox.VirtualBox Members

We can consider VirtualBox.VirtualBox COM as the core API to manage VirtualBox. The members of this object can be used to create / manage virtual machines and various other aspects of VirtualBox virtualization. We will look at each of these interfaces as we go forward. 

How can we get a list virtual machines? 

Quite simple..! Yes. It is. Similarly, we can create virtual machines using CreateMachine() method. I will talk about this in the next post. Stay tuned..

Filed under: PowerShell, Scripting, VirtualBox, Virtualization


Ravikanth is a principal engineer and the lead architect for Microsoft and VMware virtualized and hybrid cloud solutions within the Infrastructure Solutions Group at Dell EMC. He is a multi-year recipient of Microsoft Most Valuable Professional (MVP) award in Windows PowerShell (CDM) and Microsoft Azure. Ravikanth is the author of Windows PowerShell Desired State Configuration Revealed (Apress) and leads Bangalore PowerShell and Bangalore IT Pro user groups. He can be seen speaking regularly at local user group events and conferences in India and abroad.