1

I have been scripting the creation of my Hyper-V VMs with vbscript successfully for sometime now. All the technician has to do is run my script, select the type of server they are building (EG. a Web server, SQL server, etc) and all the appropriate virtual resources are allocated (so the RAM size, disk size etc will differ depending on the function of the server).

The problem I now have is that I need to ammend the script to add a second VHD. It can either be added as secondary drive on IDE Controller 0, or it can be added to IDE Controller 1 (leaving the primary drive on IDE Controller 0).

I posted this question on StackOverflow on 22/02/12: https://stackoverflow.com/questions/9395823/scripting-the-addition-of-a-second-vhd-to-a-hyper-v-vm. I've had avery few hits and no responses so far.

I cannot work out how to modify the existing code to add the second VHD!

I suppose there are two options:

  1. Modify my script replacing the existing functions with a different programatic approach. Any ideas?
  2. If anyone knows how to do this using the command line, I can quite easily incorporate that approach into my script using the shell object.

I'm open to any suggestions.

Thank you.

Fitzroy
  • 321
  • 2
  • 4
  • 8
  • 1
    You've tagged this as `vbscript` so I assume that's the language you're using? Do you need to continue that or could you switch to say, powershell? – Mark Henderson Feb 23 '12 at 23:33
  • Hi, yes I'm currently using vbscript. I suppose I could move enitirely toa powershell solution, however my prefered approach would be to modify the vbscript. A bit kludgy perhaps, but would it be possible to remove the existing functions from my script that a responsible for creating the virtual IDE controller(s) and attaching the VHD(s) and instead make a call to a powershell script, once the powershell script has finished then continue running the remainder of my script as usual. – Fitzroy Feb 24 '12 at 00:06
  • If you have a look at the stackoverflow link I posted, you'll get a better idea of what I'm currently doing: http://stackoverflow.com/questions/9395823/scripting-the-addition-of-a-second-vhd-to-a-hyper-v-vm. – Fitzroy Feb 24 '12 at 00:10

1 Answers1

0

There are 3 WMI objects you need to take care of when you create/modify a virtual harddisk in Hyper-V: Controller, Drive and VHD. Only Controller is automatically created with VM creation.
To create a Drive object, you need to clone a hardDrive definition which is an Msvm_ResourceAllocationSettingData object, set its parent to the path of Controller object and its Address to '0' or '1' To create a VHD object, clone a VHD definition which is of the same WMI class, and set Connections to the VHD file path.

There is also a Powershell library for Hyper-V http://pshyperv.codeplex.com/

woodings
  • 195
  • 1
  • 11