Scripting launch dependencies under Virtual Server

With more complex virtual machine configurations you might find that you have dependencies on the order in which virtual machines should be launched (for instance one virtual machine may be a domain controller – while the other virtual machines are members of that domain).  There are two ways to handle this in an automated fashion under Virtual Server.  One is to set the virtual machines to start automatically and set appropriate start delay values for each virtual machine.  The second option is to use a script like this:

‘ || Script begins

‘ Connect to Virtual Server

Set virtualServer = CreateObject(“VirtualServer.Application”)

‘ Create virtual machine objects
Set vm1 = virtualServer.FindVirtualMachine(“Virtual Machine 1”)
Set vm2 = virtualServer.FindVirtualMachine(“Virtual Machine 2”)

‘Start first virtual machine

‘Ignore errors on the next little section
On Error Resume Next

‘Loop until vm1 returns a heartbeat
while not vm1.GuestOS.IsHeartbeating
 wscript.sleep 500

‘Listen to error messages again
On Error GoTo 0

‘Start second virtual machine

‘ || Script ends

This script launches the first virtual machine and then waits for the virtual machine heartbeat to return before launching the second virtual machine.  This is a very robust solution as the virtual machine heartbeat will not return until most of the services are up and running on the virtual machine.  It should be noted that it is important to handle errors in the middle of this script as until the virtual machine has loaded the Virtual Machine Additions component requesting the value of the heartbeat will return an error.