Jaa


Hyper-V VM Tribbles – VMs Everywhere!

image

I was thinking this week of how to demonstration / highlight the cool new processing capacity of new multi-core processors.

I came up with a really short PowerShell script (based on James O’Neill’s Hyper-V management library available on Codeplex) that creates a specific number of VMs on Hyper-V using a base VHD file and differencing disks.  It’s really easy, and ultimately could be the basis for any home grown Virtual Desktop Infrastructure or “cloud on demand” service.

The script is really very simple – here’s the copy I used to make the screen shot shown:

# requires Hyper-V Management Library from Codeplex (https://pshyperv.codeplex.com/)
#uses defaults for RAM and does not setup NIC - easy to adjust

$MaxVMs = 24
$Diff_Dir = "C:\ClusterStorage\Volume1\DIFFs"
$BaseVM = "C:\ClusterStorage\Volume1\VDI_Fun\WS2008R2_EnterpriseCore_x64.vhd" 
$index = 1
do {
$new_VM_name="Dif_VM_$($index)"
$new_VHD_name="$($Diff_Dir)\Diff$($index).vhd"
new-vhd $new_vhd_name -parentVHD $BaseVM -wait
$myVM = (new-VM $new_vm_name)
add-vmdisk $myVM 0 0 $new_VHD_name
Start-VM $myVM
new-vmconnectsession -vM $myVM
# next line WAITS for the new VM to respond before going on... comment out for more RAPID provisioning
# test-vmheartbeat $myVM -timeout 300
$index++
}
While ($index -le $MaxVMs)

So what did this snippet do on a server in my tiny little lab?  It quickly created 24 VM's based on a single Windows Server 2008 R2 Core installation VHD I had previously created!  This sort of script works against Hyper-V Server (and even runs on Hyper-V Server 2008 R2 since it has PowerShell support!).

Can you imagine how easy (and cheap) it could be to spin up VMs of all kinds with scripts like this!  It’s even better with the System Center tools, but you can’t beat the price of Hyper-V Server 2008 R2 and the PowerShell library on Codeplex!.

-John

Comments

  • Anonymous
    January 01, 2003
    thanks for the link I'll take a look at it! tr

  • Anonymous
    January 01, 2003
    just saved me a bunch of time, was just starting to create a script just list this! thanks

  • Anonymous
    January 01, 2003
    Tony - Glad you found it useful! I'm pretty busy the next few weeks, but Michael Greene (http://blogs.technet.com/migreene/) and I are going to play around with this a bit and work out some other interesting scenarios as time permits. -John

  • Anonymous
    January 01, 2003
    The comment has been removed

  • Anonymous
    January 01, 2003
    Tony - I haven't done VDI work with CSV which sounds like the scenario you are proposing.   I like using differencing disks for VDI sometimes, it saves disk and speeds up provisioning of new VMs.  I'm not keen on using differencing disk for other than test or VDI. I'm not clear why you would use differencing disk with CSVs for VDI.  That means you are making "disposable" VMs highly availble?   It might make sense to be able to provision off of a single VHD - but that seems expensive to me.  Here's a post that goes through that sort of thing from September that might be an interesting read:  https://blogs.technet.com/ddc_dudes/archive/2009/09/08/rapid-provisioning-with-scvmm-2008-r2.aspx