MDGHOST builds differencing disks based on parent drives. In a test lab I find this useful because I usually have sysprepped parent drives for each OS ready to go. the script will build VM's very quickly, without the need for SCVMM. I find this useful in single machine scenarios, and I’m spoiled on it, because it’s DANG FAST. Mdghost requires powershell be run as administrator (much of the Hyper-V cmdlets need admin access to function properly.)
Note that in the sample below, I set my execution policies to unrestricted. This may not be copacetic in your corporate environment, so please evaluate the trustworthiness of any script (including mine) and be a good citizen of your corporate network environment. The script is primarily intended to build test labs.
The script works on 2012, and Windows 8 Hyper-V.
Edit the script to change your defaults:#initializedefaults
$ParentDef ="w2k8r2datacenterbase" <-Default Parent Drive
$Namedef ="Scratch" <- Default Prepended Name for Scratch VHDS
$Networkdef ="Scratchnet" <- Default Network Name
[int64]$Memdef =1024MB <- Default RAM settings
$Procdef =2 <- Default Number of processors
$ParentDir = "c:\ParentDrives" <- Location of Parent Drives
$global:VHD="v:\VirtualDisks\" <- Where the system will place differencing disks
$procval=1,2,4 <-Acceptable Processor Values
[int64]$maxmem=4192MB <-Maxmem defaults
PSC:\hvml> . .\MDGHOST.ps1
. : FileC:\hvml\MDGHOST.ps1 cannot be loaded because running scripts is disabled onthis system. For more information, see about_Execution_Policiesat http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:3
+ CategoryInfo :SecurityError: (:) , PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
PS C:\hvml> Set-ExecutionPolicy unrestricted
PS C:\hvml> Get-ExecutionPolicy
PS C:\hvml> . .\MDGHOST.ps1
*Note that the script must be dot sourced. That's a . then a space, then a path to the script file. This is a common mistake. If you type mdghost -help and don't get anything, it's the most likely cause.
PS C:\hvml> mdghost -help
mdghost[parent] [newvhd] [net] [mem] [cpu] [help] [go]
At this point you can use MDGHOST to create VM’s VERY, VERY QUICKLY. You can build machines as fast as your hardware will allow. Just typing mdghost will prompt you for all the defaults, with a randomly generated VHD Name (useful if you don’t care, or will rename them later).
Parent:w2k8r2datacenterbase.vhd VHD:Scratch-18AEDCC9 Net:10.0.x.y Memory:1024MB CPU:2
The –go swtich allows you to skip the prompt. If the –parent and –net values passed are ambiguous, the script will prompt you with a numbered list.
Parent:w2k8r2datacenterbase.vhd VHD:Scratch-1ADFCFDD Net:10.0.x.y Memory:1024MB CPU:2
PS C:\hvml>mdghost -parent r2
That's really usefull to deploy new VMs quickly. Great article!
FWIW - Found in a hyper-v demo that this is not working with vhdx parents. Working on a new rev. The people that have come to me for help with the script are generally running into two problems:
1. Defaults not defined properly
2. Not dot sourcing the script
Parent Drives for the moment must be .vhd, not .vhdx. New Version will include support for dynamic memory.
Planned enhancements for next version include writing defaults to the registry, and prompting for creation of default switch.
If you've created a VM with VHDX you can convert it to VHD as described in the following post https://blogs.technet.com/b/cbernier/archive/2013/08/29/converting-hyper-v-vhdx-to-vhd-file-formats-for-use-in-windows-azure.aspx