Wednesday, August 20, 2014

Part - 7 : PowerShell and Hyper-V : Adding Virtual Disk to the Virtual Machines in Hyper-v

 

In my previous post, we see that how can we create a new virtual hard disk.

If you remember yesterday we have creates a 5Gb of fixed hard disk image with the name of "myHDDFixed.vhd".

Today, we are going to add the same  virtual disk which we have created yesterday to the one of our prebuilt virtual machine.

As you know that we can use the Get-VM cmdlet to get the list of all of our virtual machines.

In the below screenshot, you can see all of my virtual machines. We are going to add the virtual hard disk to the  "Windows 2008 R2" virtual machine.

2

In the below screenshot you can see that there are no secondary hard disk in the "Windows 2008 R2" virtual machine.

1

Remember : We can only add virtual hard disk to the virtual machines, when they are Powered Off, You can't add virtual disk if the virtual machines in Powered ON.

Let's store the information of the "Windows 2008 R2" in to a variable, as we need this information as "Virtual Machine" object not as a plain string.

$vm = Get-VM -Name 'Windows 2008 R2'
3

We use the "Add-VMHardDiskDrive" cmdlet to add the virtual hard disk to the virtual machine.


The basic syntax of Add-VMHardDiskDrive is simple, we need to provide the path of the virtual hard disk file which we need to add to the virtual machine and the  name of the virtual machine as Virtual machine object.


In our case the the path of the virtual hard disk is "'F:\VirtualMachines\Hyper-V\myHDD\myHDDFixed.vhd' and the virtual machine is "Windows 2008 R2" , and we stored the Virtual Machine Object in $vm variable.


Add-VMHardDiskDrive -Path 'F:\VirtualMachines\Hyper-V\myHDD\myHDDFixed.vhd' -VM $vm

in the below screenshot, you can see that our command has run successfully.


4


Let's start the virtual machine and see if the new hard disk is added successfully.


5


If you check the setting of "Windows 2008 R2" virtual machine, you can see that, our "myHDDFixed.vhd" is added successfully.


6


When i opened the "Disk Management" on "Windows 2008 R2", it's showing me that one disk is added and i need to initialize it.


7


After initialize, you can see that a new 5GB of hard disk is added to the server. Smile 


8





Simple.. and easy... isn't..........


 tumblr_mfxux9bqN61qzmvsio8_250


Take care of yourself, and keep smiling, World need You..


Thanks.


Aman Dhally


If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube” channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.

Tuesday, August 19, 2014

Part - 6 : PowerShell and Hyper-V : Create new Hyper-V virtual Hard Disks.

 

Creating new virtual hard disk are the one of the major tasks which we done on virtual Machines. In Hyper-V creating a new virtual disk  using PowerShell is very easy and straight forwarded process.

Without going much deeper, today we will create a simple virtual hard disk. To create a new virtual disk we do use the "New-VHD" cmdlet.

We can create a "Fixed Size" disk or a  "Dynamic" disk. The only difference between them is, if you create a "Dynamic Disk" of 5GB, it only occupied the same as much has data it store, For example, if you create a 5GB of Dynamic Disk, and it has data of 3GB, then it occupied only 3 GB of disk space.

If we create a "Fixed Size" disk, then it doesn't matter how much data it may contain, it will use the full 5GB of Disk space.

Remember : By default " New-VHD" do create a Dynamic type of disk.

The Syntax is simple, use New-VHD and provide a path where you want to create  a virtual disk (name with extension) and provide the size in GB, simple

" New-VHD -Path 'F:\VirtualMachines\Hyper-V\myHDD\myHDDynamic.vhd' -SizeBytes 5GB"

In above command , we are creating a new virtual hard disk name "myHDDynamic.vhd' "  with the size of 5GB.

1

In the above screenshot , you can see that our command is completed successfully.

In the below screenshot, you can see that "Virtual Disk" is created, but the size of disk is only 16KB, Why? if you remember as I have mentioned above that by default "New-VHD " do create dynamic disk.

2 

Now, if you want to create a "Fixed Size" virtual hard disk, we need to use the -Fixed parameter with the above command.

  New-VHD -Path 'F:\VirtualMachines\Hyper-V\myHDD\myHDDFixed.vhd' -SizeBytes 5GB -Fixed

In the above command, we are creating a new virtual hard disk with the name of "myHDDFixed.vhd' " of 5GB in size, and we have provided the -Fixed parameter to define that we need a fixed type of hard disk not dynamic one.

3

You may notice, that this time, the creation of new virtual hard disk may took long time, this is because that it really creating a 5GB of disk image.

In the below screenshot, you can notice that the new hard disk image is really of 5GB of file size.

4

That's all for today, tomorrow we will mount these hard disk to the virtual machines.

Take care and keep smiling.

tumblr_n12e6gTe9d1st0dt8o8_250

Thanks.

Aman Dhally

If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube” channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.

Wednesday, August 13, 2014

Part - 5 : PowerShell and Hyper-V - Creating Hyper-V Virtual Machine's Checkpoint Snapshots.


Sometimes, we need to save the current state of the virtual machines, as an example, if you are testing some software and want to know, how installation and uninstallation  may went and if something bad happen during testing, you can revert back to checkpoint. Or if you created and patched a Virtual Machine, and before joining it to domain, you want to create a Snapshot so that, if something may went wrong, we can revert back to the old stage.
There are lot's of other reason for creating a snapshots of the virtual machines.
We can create Checkpoint (A.K.A Snapshots) using Hyper-v Cmdlet. We do use "Checkpoint-VM" cmdlet to create snapshots.
We mainly need to pass two parameters, -Name and -SnapshotName , in -Name we have to provide the name of the virtual machine whose snapshot we want to create and in -SnapshotName parameter, we just need to provide the description of the checkpoint.
Let's create a checkpoint.
Import-Module Hyper-VCheckpoint-VM -Name 'MediaWiki' -SnapshotName "Checkpoint Crated using POSH"

In the above command, we are creating a checkpoint for our "MediaWiki" virtual machine and in description, we are saying "Checkpoint created using Posh"

In the below screenshot, you can see that, it has started creating "Checkpoint".

Capture

In the below screenshot, you can see that our command has completed without throwing any error.

 Capture_2

If you open "Hyper-V Manager" GUI console, you can see that, our checkpoint is successfully created.

Capture_3



That's all for now, see you in next blog posts.

tumblr_n12e6gTe9d1st0dt8o3_250



Thanks.

Aman Dhally

If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube” channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.