@echo off setlocal enabledelayedexpansion echo VM Selection Dialog. Only use numbers for the amounts or Shenanigans will occur! ::This is where the order of the VM's is printed as a sort of Table of Contents echo Order will be echo --------------------------------------------------------- echo 1. server08advanced.vhd, echo 2. Server2008wSQL Hard Disk.vhd, echo 3. server08core.vhd, echo 4. Windows 7.vhd, echo 5. centos6.5vm.vdi echo 6. centos65 echo 7. centos65websvr echo --------------------------------------------------------- echo. ::This is where the User is queried as to how many they want of each machine, with the default being 0 (none) echo How many server08advanced Hard Disks do you want copied SET /P server08advancedCount=(default is 0): || set server08advancedCount=0 echo. echo How many Server2008wSQL Hard Disk Disks do you want copied SET /P server08SQLCount=(default is 0): || set server08SQLCount=0 echo. echo How many server08core Hard Disks do you want copied SET /P serverCoreCount=(default is 0): || set serverCoreCount=0 echo. echo How many Windows 7 Hard Disks do you want copied SET /P win7Count=(default is 0): || set win7Count=0 echo. echo How many centos6.5vm Hard Disks do you want copied SET /P centos6.5Count=(default is 0): || set centos6.5Count=0 echo. echo How many centos65 Hard Disks do you want copied SET /P centos65Count=(default is 0): || set centos65Count=0 echo. echo How many centos65websvr Hard Disks do you want copied SET /P centos65websvrCount=(default is 0): || set centos65websvrCount=0 echo. ::This is where the user is asked whether they want to clean out C:\Temp. And if they do, then that is done. echo Do you wish to remove the existing VM's (Y/N/Other), echo default is Y, N will add the number of VHD's requested echo to the ones there already (for each type), SET /P cleanup=any other value will overwrite: || set cleanup=Y echo %cleanup% | findstr /R /I "^Y.*" && ( echo. echo Removing Existing VHD's in C:\Temp. echo If there are none, ignore the next errors. attrib -r c:\Temp\*.vhd del C:\Temp\*.vhd /F /Q attrib -r c:\Temp\*.vdi del C:\Temp\*.vdi /F /Q ) ::This is where the loop begins. The :locStartOfTesting is intended for Hard Disk specific variable settings to enable modularity within the loop. ::the echo. echo. :locStartOfTesting IF NOT !server08advancedCount!==0 ( SET countVar=server08advanced SET machineName=server08advanced SET machineExtension=.vhd SET machineLocation=C:\Virtual Machines\Server 2008 goto fnOuterLoop ) IF NOT !server08SQLCount!==0 ( SET countVar=server08SQL SET machineName=Server2008wSQL Hard Disk SET machineExtension=.vhd SET machineLocation=C:\Virtual Machines\Server 2008 goto fnOuterLoop ) IF NOT !serverCoreCount!==0 ( SET countVar=serverCore SET machineName=server08core SET machineExtension=.vhd SET machineLocation=C:\Virtual Machines\Server 2008 goto fnOuterLoop ) IF NOT !win7Count!==0 ( SET countVar=win7 SET machineName=Windows 7 SET machineExtension=.vhd SET machineLocation=C:\Virtual Machines\Windows 7 goto fnOuterLoop ) IF NOT !centos6.5Count!==0 ( SET countVar=centos6.5 SET machineName=centos6.5vm SET machineExtension=.vdi SET machineLocation=\\mefit10\learn\intranet goto fnOuterLoop ) IF NOT !centos65Count!==0 ( SET countVar=centos65 SET machineName=centos65 SET machineExtension=.vdi SET machineLocation=\\mefit10\learn\intranet\centos65 goto fnOuterLoop ) IF NOT !centos65websvrCount!==0 ( SET countVar=centos65websvr SET machineName=centos65websvr SET machineExtension=.vdi SET machineLocation=\\mefit10\learn\intranet\centos65websvr goto fnOuterLoop ) goto locEndOfTesting :fnOuterLoop SET loopCounter=1 SET loopOffset=0 echo %cleanup% | findstr /R /I "^N.*" && ( FOR %%F in (C:\Temp\*!machineExtension!) DO ( SET str1=%%F call SET str2=!str1:%machineName%=! IF NOT !str2!==!str1! ( SET /A loopOffset=!loopOffset!+1 ) ) SET /A loopCounter=!loopCounter!+!loopOffset! ) :fnInnerLoop echo This is %machineName% VHD #%loopCounter%. echo Please be patient during the copying process. XCOPY /y /f "%machineLocation%\%machineName%%machineExtension%" "C:\Temp\%machineName%-%loopCounter%%machineExtension%"* attrib -r "C:\Temp\%machineName%-%loopCounter%%machineExtension%" echo. IF %loopCounter% GTR 1 ( echo. echo Changing UUID of Alternate Hard Disk "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" internalcommands sethduuid "C:\Temp\%machineName%-%loopCounter%%machineExtension%" echo. ) SET /A loopCounter+=1 IF %loopCounter% LEQ !%countVar%Count! ( goto fnInnerLoop ) else ( SET %countVar%Count=0 goto locStartOfTesting ) :locEndOfTesting echo. echo. echo Be sure to edit each Virtual Machine -before- you start it echo by clicking Settings--Network and then opening the Advanced Tab. echo. echo Select Attached to... Bridged Adapter, echo and Adapter type... Intel Pro/1000 Desktop. pause