Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 36188

Create Virtual Machines Quickly using MDGHOST - Part 1

$
0
0

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. 

How to use the script

 

Edit the script to change your defaults:

#initialize
defaults

$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

 

Usage:

 

PSC:\hvml> . .\MDGHOST.ps1

. : File
C:\hvml\MDGHOST.ps1 cannot be loaded because running scripts is disabled on
this system. For more information, see about_Execution_Policies
at http://go.microsoft.com/fwlink/?LinkID=135170.

At line:1 char:3

+ .
.\MDGHOST.ps1

+  
~~~~~~~~~~~~~

   
+ CategoryInfo          :SecurityError: (:) [], PSSecurityException

   
+ FullyQualifiedErrorId : UnauthorizedAccess

 

PS C:\hvml> Set-ExecutionPolicy unrestricted

 

PS C:\hvml> Get-ExecutionPolicy

Unrestricted

 

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). 

 

PS
C:\hvml> mdghost

 Parent:w2k8r2datacenterbase.vhd  
VHD:Scratch-18AEDCC9 Net:10.0.x.y  Memory:1024MB CPU:2

Confirm
(y/n): y

 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

Confirm
(y/n):

PS C:\hvml>
mdghost -parent r2

 

ID Parent
VHD             

--
----------             

0 w2k8r2datacenterbase.vhd

1 w2k8r2scSysprep.vhd    

 Which one?: 

 


Viewing all articles
Browse latest Browse all 36188

Trending Articles