Monday, April 13, 2009

Reconnect VHD Parent Disk

Dear my readers,

As stated in a previous blog, there is three main types of the disks.

the Child and parent disks where you can have some sort of base disk contains all sysprepped image of the windows and another child disk contains the currently running system like base for windows 2003 sp2 and multiple child disks contains different applications

anyway what I am trying to address is when you move your parent files to another directory and try to open the child VHDs in your VMs you will get a message in Virtual PC saying please locate your Parent disks, but if you are using HyperV you will get error message which says you cannot start the machine due to disk failure….

You can use the WMI to connect back your Child disk with the parent in the new location

we will declare variable for the wmi class we working with.

$vhd=gwmi Msvm_ImageManagementService –namespace root\virtualization –comp $computer

we will define the disks as variables

$child=c:\vhds\child.vhd

$parent=c:\vhds\parent.vhd

we will define the computer we are trying to connect to in the $computer variable; if it localhost we will use “.” dot if it is remote we will use the accessible hostname or netbios name.

$computer=.

now it is ready to use our method ReconnectParentVirtualHardDisk which help us the solve the problem stated above, as we learnt before that if we want to know how to use certain method then we use get-member and look for the syntax in the definition

$vhd |gm ReconnectParentVirtualHardDisk |fl

TypeName   : System.Management.ManagementObject#root\virtualization\Msvm_ImageManagementService
Name       : ReconnectParentVirtualHardDisk
MemberType : Method
Definition : System.Management.ManagementBaseObject ReconnectParentVirtualHardDisk(System.String ChildPath, System.String ParentPath, System.Boolean Force)

so now we will connect the child to new parent.

$vhd.ReconnectParentVirtualHardDisk($child,$parent,1)