Page 1 of 1

Start several VMs at the same time.

Posted: 2. Jun 2009, 22:38
by sct_nicolaus
Hi. Im looking for a smart method to start all my VMs at the same time.

I got X number of VMs, all with Windows XP guests, and all named WinXP1, WinXP2, WinXP3, ... , WinXPX.

Right now i've made a batchfile like this:

vboxmanage startvm "WinXP1"
vboxmanage startvm "WinXP2"
vboxmanage startvm "WinXP3"
...
vboxmanage startvm "WinXPX"

My X can increase and decrease. Right now i got to edit my batch file everytime that happens.

Is there a smart command i can use, like a loop or something, so i don't have to edit every time?

Thx

Re: Start several VMs at the same time.

Posted: 2. Jun 2009, 22:45
by Sasquatch
I'm sure you can. You have to check a folder and read it's contents for example. You can do a count on the amount of folders it has, or files. Or even read the names of the folders which you can put in a variable and use that to pass to the startvm parameter. This idea can be found on countless sites, if you search properly. The trick is the "for" loop. E.g. "for x in $var; do <command>; x + 1". Something like that.

Re: Start several VMs at the same time.

Posted: 2. Jun 2009, 22:59
by sct_nicolaus
I've just tried this:

----
echo off
SET /P amount= How many VMs?

FOR /L ?? IN (1,1,%amount%) DO "vboxmanage startvm "WinXP%number%"
----

where %number% is the current VM it gotta start.
the (1,1,%amount%) will make it run from 1 to %amount%, with an increment of 1.

The trick is to tell which number I'm at. Also, I dont really know what that first variable does where i wrote ??.

Re: Start several VMs at the same time.

Posted: 3. Jun 2009, 10:05
by Sasquatch
I'm sure you can find some tutorials for scripting in Windows that tell you exactly where to put what. Even the MS site has some examples (check their MSDN site).
It's more fun if you figure it out on your own than when someone makes a script for you. You can do so much more that way :). I've already given you a gentle push in the right direction. Good luck.

Re: Start several VMs at the same time.

Posted: 3. Jun 2009, 13:01
by sct_nicolaus
Hehe, fair enough. Thanks ;)