Batch Scripts

A screenshot of the operation of the VM Copying Batch Script I wrote to facilitate my Network Admin Certificate at TAFE. Fetching the requested number of copies of of the requested machines from their home on the local network and doig various housekeeping tasks automatically.

Here is a batch file I created for my TAFE System Aministration course in 2014 which:

  • Copies a configurable number of server08advanced, server08core and Windows 7 Virtual Hard Disks (VHD’s) for usage from a read only area of the hard disk to a read/write area
  • Creates a duplicate of the copied VHD in the same area if more than one is required, and adds a number to the end of the filename
  • Modifies the Attributes of the copied VHD’s so that they are no-longer read only and are able to be used by VirtualBox as a VHD
  • Generates a new UUID for the duplicate VHD’s to allow for concurrent usage by VirtualBox
  • Modifies the attributes of all the VHD’s so that they are no-longer read only
  • Allows for the user to specify whether they want to:
    • Clear the target directory (where the VHD’s will be copied to) of all pre-existing VHD’s
    • Leave any pre-existing VHD’s in the target directory and just copy over new ones and change their UUID’s (which picks up adding the number to the end of the filename from the number of VHD’s it detects already in the folder)
    • Leave any pre-existing VHD’s in the target directory and just overwrite them if a conflict arises
  • Outputs further instructions after the script completes it’s other functions, which are required to automatically install the appropriate network interface drivers for the VHD’s

For some reason the copies seem to take quite some time despite explorer displaying them as having successfully copied far sooner than is indicated by the script.

After about the second version I swapped from using solely programmatic loops to using a mixture of those and goto’s. Though I personally can’t stand the spaghetti code caused by goto, I was led to believe the loops were adding unnecessary overhead.

And so I decided to use the goto’s to emulate something akin to a function call which allowed me to further refine my code into a single loop with all of the required information being passed to it by variables. This allowed me to essentially modularise the VHD setup area.

Now a new VHD can be added by duplicating a few lines of code and changing the values of variables where appropriate, and adding in a prompt asking how many of them the user wants

Here are the various versions of the script as it has progressed, from newest to oldest (though the very oldest was overwritten).

[Latest] – menudrivenReusableModularVariableVmCopying.bat