I am a big fan of differencing VHDs as the provide tremendous power when working with large database but they also come with their own set of complications.
One of those complications that can arise is when due to files being moved or folder structures being reorganized the parent VHD of your differencing VHD is no longer accessible. After you try and attach your differencing VHD you may see an error message like this one:
We can use the following power shell from a Windows 7 PC with the latest version of Microsoft Virtual PC that comes with Windows XP Mode installed to take a look at the parent property of our differencing disk to see if something is wrong
$vpc=new-object -com VirtualPC.Application
$VHDChild = $vpc.GetHardDisk("C:\NAV2010.06.10_Diff")
$VHDChild
$VHDChild.Parent
In my case I recently changed the IP address of a NAS that was storing the parent VHD and assigned a DNS record to the NAS so that I wouldn’t have to keep track of it’s IP address but now the path to the parent VHD that is stored in my differencing VHD is no longer valid.
Thankfully this is fairly easy to fix. All we need to do is add the following code so that we get a new $VHDParent object using the corrected path and then assign that object to the Parent property of our differencing disk
$VHDParent = $vpc.GetHardDisk("\\devnas\Data_Backups SQLCluster1\NAV2010.06.10.vhd")
$VHDChild.Parent = $VHDParent
$VHDChild.Parent
Now we can attach our differencing VHD without error and get back to work =).
While I was ultimately able to make this work in my case, I did have to modify the process slightly. In my case the old location of the parent disk was on a local drive and that location had an updated version of the parent drive. This resulted in several errors. The fix was to rename the “new” parent, then apply your script. Once I was done, then rename things back. All in all, a very worth while script, thanks for posting it. Do you mind if I add this to my blog (with proper credit, of course)?
There is a easy way to change parent VHD disc path via VBS script: http://gallery.technet.microsoft.com/ScriptCenter/0b59c408-7d06-4453-89b3-eae5b766c8d9/