Jaa


Recovering VM that has snapshots but no Hyper-V Export file (last resort)

If you need to quickly recover a VM that has snapshots but no export file, you can use the commands in SCVMM R2 that enable rapid provisioning. In this case you are creating a new VM from the latest AVHD.

 

NOTE: This approach does not recreate the snapshot tree. This is simply a way of recovering your VM

if you need immediate access to it.

To get the latest AVHD:

PS C:\>$avhds = get-childitem \\vmhost01\e$\SnapshotRecover01 -Filter "*.avhd" -Recurse | sort-object @{Expression={$_.LastWriteTime-$_.CreationTime}; Ascending=$true}

The first AVHD in this list should be the latest one. From the object you want to tease apart the location of the AVHD and the file name

PS C:\> $avhds[0].directoryname, $avhds[0].name

\\ vmhost01\e$\SnapshotRecover01

SnapshotRecover01_disk_1_37BD309A-C4B3-4196-A698-485B7BADF8AE.avhd

PS C:\>

Now that you have the Path to the AVHD and the AVHD file name, use SCVMM to create a new VM from the existing disk

(1) PS C:\> $guid = [guid]::NewGuid()

(2) PS C:\> $vmhost = Get-VMHost | where {$_.Name -match "vmhost01"}

(3) PS C:\> $vhd = @(Get-VirtualHardDisk | where {$_.Name -Match "large"})

(4) PS C:\> New-VirtualDiskDrive -VirtualHardDisk $vhd[0] -IDE -BUS 0 –LUN 0 -Path "E:\SnapshotRecover01" -Filename "SnapshotRecover01_disk_1_37BD309A-C4B3-4196-A698-485B7BADF8AE.avhd" -JobGroup $guid

(5) PS C:\> New-vm -VMHost $vmhost -Name "SnapshotRecover01_01" -Path "E:\snapshotrecover01" -JobGroup $guid -UseLocalVirtualHardDisks -Description "" -Owner "contoso\user01" -CPUCount 1 -MemoryMB 512 -VMMServer localhost –SkipInstallVirtualizationGuestServices

Step by step

1. Create a guid that will be used for the jobgroup

2. Get the vm host object where you want to create the vm

3. Get ANY vhd from the library. Doesn’t matter which one. The next cmdlet simply needs a placeholder. Use the blank VHDs that ship with VMM for example. This VHD does NOT need to be the snapshot aVHD!

4. Pass the path to the AVHD and the AVHD file name (retrieved from the host earlier) to New-VirtualDiskDrive. Use the VHD placeholder here. The absolute paths you specify here are from the VM host that contains the AVHD (nothing to do with Library).

5. Call the New-VM cmdlet with –UseLocalVirtualHardDisks parameter. This instructs New-VM to skip the BITS deployment and look for the disks you specified in New-VirtualDiskDrive. Use –SkipInstallVirtualizationGuestServices to avoid installing IC.

Disclaimer: This method is simply a quick way of getting the VM up and running. This method does not allow you to restore snapshot information or save state. There is always risk of using the wrong AVHD, so keep that in mind when you do this.