Search This Blog

Tuesday, April 16, 2013

Creating Virtual Machine Using Powershell–Part 2

In our previous post, we have talked about converting sysprep image and create new virtual hard disk. We will continue to talk about an additional three cmdlet when creating virtual machine. The next step is create virtual machine configuration file with the converted sysprep image.

Example:-

VM Name Start Up Memory VHD Path Virtual Switch Name
Donut 1 GB C:\ClusterStorage\Volume1\Donut\ vSwitch-Production
Eclair 2 GB C:\ClusterStorage\Volume1\Eclair\ vSwitch-Production
Froyo 4 GB C:\ClusterStorage\Volume1\Froyo\ vSwitch-Production
Gingerbread 2 GB C:\ClusterStorage\Volume1\Gingerbread\ vSwitch-Production
HoneyComb 2 GB C:\ClusterStorage\Volume1\HoneyComb\ vSwitch-Backup
Ice Cream 2 GB C:\ClusterStorage\Volume1\IceCream\ vSwitch-Production

The virtual machine configuration and virtual hard disk are stored in Cluster Shared Volume. Some VMs are using vSwitch-Production virtual switch and 1 VM is using vSwitch-Backup. The VM boot up with the amount of memory that defined in start up memory.

Cmdlet:-

1. Cmdlet 3:- New-VM –> to create new VM Configuration with the setting as listed above

VM 1:- Donut
new-vm –name Donut -MemoryStartupBytes 1GB -VHDPath C:\ClusterStorage\Volume1\Donut\DonutDisk1.vhdx -SwitchName vSwitch-Production

VM 2:- Eclair
new-vm –name Eclair -MemoryStartupBytes 2GB -VHDPath C:\ClusterStorage\Volume1\Eclair\EclairDisk1.vhdx -SwitchName vSwitch-Production

VM 3:- Froyo
new-vm -name Froyo -MemoryStartupBytes 4GB -VHDPath C:\ClusterStorage\Volume1\Froyo\FroyoDisk1.vhdx -SwitchName vSwitch-Production


VM 4: Gingerbread
new-vm Gingerbread -MemoryStartupBytes 2GB -VHDPath C:\Clusterstorage\Volume1\Gingerbread\GingerbreadDisk1.vhdx -SwitchName vSwitch-Production


VM 5:- HoneyComb
new-vm HoneyComb -MemoryStartupBytes 2GB -VHDPath C:\ClusterStorage\Volume1\HoneyComb\HoneyCombDisk1.vhdx -SwitchName vSwitch-Production


VM 6:- Ice Cream
new-vm IceCream -MemoryStartupBytes 2GB -VHDPath C:\ClusterStorage\Volume1\IceCream\IceCreamDisk1.vhdx -SwitchName vSwitch-Production

2. Cmdlet 4:- Set-VM –> to configure a virtual machine with an additional settings.

Once VM Configuration has created , let add an additional setting into our example

VM name Virtual Processor Minimum Memory Maximum Memory Automatic Start Action
Donut 2 512 MB 2 GB Nothing
Eclair 2 1 GB 6 GB Nothing
Froyo 2 Static Memory   Nothing
Gingerbread 2 1 GB 6 GB Nothing
HoneyComb 4 1 GB 6 GB Nothing
Ice Cream 4 1 GB 4 GB Nothing

 

VM 1:- Donut

set-vm Donut -ProcessorCount 2 -DynamicMemory -MemoryMinimumBytes 512MB -MemoryMaximumBytes 2GB -AutomaticStartAction Nothing

VM 2:- Eclair

set-vm Eclair -ProcessorCount 2 -DynamicMemory -MemoryMinimumBytes 1GB -MemoryMaximumBytes 6GB -AutomaticStartAction Nothing

VM 3:- Froyo

set-vm Froyo -ProcessorCount 2 -StaticMemory -AutomaticStartAction Nothing

VM 4: Gingerbread

set-vm Gingerbread -ProcessorCount 2 -DynamicMemory -MemoryMinimumBytes 1GB -MemoryMaximumBytes 6GB -AutomaticStartAction Nothing

VM 5:- HoneyComb

set-vm HoneyComb -ProcessorCount 4 -DynamicMemory -MemoryMinimumBytes 1GB -MemoryMaximumBytes 6GB -AutomaticStartAction Nothing

VM 6:- Ice Cream

set-vm IceCream -ProcessorCount 4 -DynamicMemory -MemoryMinimumBytes 1GB -MemoryMaximumBytes 4GB -AutomaticStartAction Nothing

HoneyComb and Ice Cream VM are configure to use 4 vcpu whereby the rest is set to use 2 vcpu. 2 vcpu is the supported virtual processor that we can configure for Windows Server 2003 VM. (please refer to previous post) Meanwhile, only Froyo VM is using static memory whereby the rest are using Dynamic memory features.

3. Cmdlet Add-VMHardDiskDrive – allow to add an additional hard disk to the VM

VM 2:- Eclair

Add-VMHardDiskDrive Eclair -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 0 -Path C:\ClusterStorage\Volume1\Eclair\EclairDisk2.vhdx

VM 3:- Froyo

Add-VMHardDiskDrive Froyo -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 0 -Path C:\ClusterStorage\Volume1\Froyo\FroyoDisk2.vhdx

VM 4: Gingerbread

Add-VMHardDiskDrive Gingerbread -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 0 -Path C:\ClusterStorage\Volume1\Gingerbread\GingerbreadDisk2.vhdx

VM Éclair , Froyo and Ginderbread required an additional virtual hard disk and assigned to SCSI Controller (please refer to previous post to this requirement)

In this Part 2, you have learned to create new virtual machine, configure a virtual machine and add new disk to the VM. Three cmdlet to remember:- New-VM, Set-VM and Add-VMHardDiskDrive. Stay Tuned for Part 3 for an additional cmdlet.

Relevant Post

No comments:

Post a Comment