@echo off setlocal enabledelayedexpansion SET server08advancedCount=0 SET server08SQLCount=0 SET serverCoreCount=0 SET server03Count=0 SET win7Count=0 SET centos6.5Count=0 SET centos65Count=0 SET centos65websvrCount=0 SET s2012Count=0 :locMenuStart cls 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 Please enter the number of the machine type you wish to copy across. echo Use -1 to confirm your selections and proceed. echo --- Machine Name (Current Amount to Copy) ---------- echo 1. server08advanced.vhd (%server08advancedCount%), echo 2. Server2008wSQL Hard Disk.vhd (%server08SQLCount%), echo 3. server08core.vhd (%serverCoreCount%), echo 4. Phil Server 2003 Hard Disk.vhd (%server03Count%), echo 5. Windows 7.vhd (%win7Count%), echo 6. centos6.5vm.vdi (%centos6.5Count%), echo 7. centos65 (%centos65Count%), echo 8. centos65websvr (%centos65websvrCount%), echo 9. server2012 (%s2012Count%) echo --------------------------------------------------------------------------- echo. ::This is where the user will be asked for their input in the menu section SET /P userInput=#: echo. ::This will take the user to the :locCASE_ goto associated with their choice 2>NUL goto :locCASE_%userInput% # jump to :locCASE_1, :locCASE_2, etc. IF ERRORLEVEL 1 goto :locCASE_DEFAULT # if label doesn't exist ::This is where the user will come if they enter the -1 confirmation selection :locCASE_-1 goto locAfterMenu ::This is where the User is queried as to how many they want of each machine, with the default being 0 (none) :locCASE_1 echo How many server08advanced Hard Disks do you want copied SET /P server08advancedCount=#: goto locMenuStart :locCASE_2 echo How many Server2008wSQL Hard Disk Disks do you want copied SET /P server08SQLCount=#: goto locMenuStart :locCASE_3 echo How many server08core Hard Disks do you want copied SET /P serverCoreCount=#: goto locMenuStart :locCASE_4 echo How many Phil Server 2003 Hard Disks do you want copied SET /P server03Count=#: goto locMenuStart :locCASE_5 echo How many Windows 7 Hard Disks do you want copied SET /P win7Count=#: goto locMenuStart :locCASE_6 echo How many centos6.5vm Hard Disks do you want copied SET /P centos6.5Count=#: goto locMenuStart :locCASE_7 echo How many centos65 Hard Disks do you want copied SET /P centos65Count=#: goto locMenuStart :locCASE_8 echo How many centos65websvr Hard Disks do you want copied SET /P centos65websvrCount=#: goto locMenuStart :locCASE_9 echo How many Server 2012 Hard Disks do you want copied SET /P s2012Count=#: goto locMenuStart ::This is where the user will come if they didn't enter a valid input :locCASE_DEFAULT echo I'm sorry, I didn't quite understand what you meant by that entry... Press any key to try again pause ::After asking for the amount of machines for that particular selection, return to the selection menu goto locMenuStart :locAfterMenu ::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 Ignore the file not found errors, if any. 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 !server03Count!==0 ( SET countVar=server03 SET machineName=Phil Server 2003 Hard Disk SET machineExtension=.vhd SET machineLocation=C:\Virtual Machines\Scripting 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 ) IF NOT !s2012Count!==0 ( SET countVar=s2012 SET machineName=s2012 SET machineExtension=.vdi SET machineLocation=\\mefit10\learn\OracleVMvirtualDisks 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