Convert VMware OVA to Hyper-V Virtual Hard Disk (VHD)

Audience
Public
Product
FlashArray
Content Type
Source Type
Knowledge Base

Convert VMware OVA to Hyper-V Virtual Hard Disk (VHD)

KB0014040
Pure Product
FlashArray
Symptoms

For customers or partners running Microsoft Hyper-V as a primary or secondary virtualization platform, this article serves as an example of how to convert an OVA to a Microsoft Hyper-V Virtual Hard Disk (VHD), Generation 1 format. OVAs use the Open Virtualization Format (OVF) to package all of the contents of a VMware application (MF, OVF, and VMDK files). 

To understand more about Hyper-V Gen1 vs Gen2, read the following article https://technet.microsoft.com/en-us/library/dn440675%28v=sc.12%29.aspx?f=255&MSPPError=-2147217396.

Resolution

Using the Microsoft Virtual Machine Converter PowerShell Module a script can be written to convert and import a VMware OVA into a Hyper-V instance as a VHD file. The below demonstration video illustrates how the end-to-end process works. 

Windows PowerShell Script Edit section
Script Requirements Edit section
  • Script must be run from a Windows Server host which has the Hyper-V Role installed.
  • Windows Management Framework (WMF) 5.0 or greater. Refer to the Microsoft Docs for all the latest information on Windows PowerShell.
  • Microsoft Virtual Machine Converter PowerShell Module - This is used to convert the OVA to a VHD.
  • 7Zip PowerShell Module (7Zip4PowerShell) - This is used to unzip the OVA.

The native Expand-Archive PowerShell cmdlet in WMF 5+ encounters errors when extracting the OVA. Example:

01 New-Object : Exception calling ".ctor" with "3" argument(s): "End of Central
02 Directory record could not be found."
03 At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Arch
04 ive\Microsoft.PowerShell.Archive.psm1:933 char:23
05 + ... ipArchive = New-Object -TypeName System.IO.Compression.ZipArchive -Ar ...
06 +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
07     + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvoca
08    tionException
09     + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power
10    Shell.Commands.NewObjectCommand
Script Source  Edit section
01 <#
02 #  Name: New-ActiveClusterMediatorVM.ps1
03 #  Version: 0.5
04 #  Purpose: Convert VMware OVA to Hyper-V VHD.
05 #>
06 #Requires -Version 5
07 Clear-Host
08  
09 # Set default variables.
10 $ACMDirectory "D:\ACM"
11 $VMName "AC-MediatorTest"
12 $HyperVHost "localhost"
13 $OVAName "<NAME>.ova"
14 $SourceOVAPath "$ACMDirectory\$OVAName"
15 $DestinationVHDPath "$ACMDirectory\$VMName.vhd"
16 $vSwitchName "vSwitch"
17  
18 # Import the Microsoft VM Converter Powershell Module.
20 Import-Module "C:\Program Files\Microsoft Virtual Machine Converter\MvmcCmdlet.psd1"
21 Import-Module -Name 7Zip4Powershell
22  
23 # Unzip the <Name>.ova file to specified directory. An OVA is just a ZIP (TAR) file containing contents.
24 Copy-Item -Path $SourceOVAPath -Destination "$ACMDirectory\$VMName.zip"
25 Expand-7Zip -ArchiveFileName "$SourceOVAPath" -TargetPath "$ACMDirectory\$VMName"
26  
27 # Find VMDK to convert to VHD.
28 $VMDKName = (Get-ChildItem -Path "$ACMDirectory\$VMName" -Filter *.vmdk).Name
29 $SourceVMDKPath "$ACMDirectory\$VMName\$VMDKName"
30  
31 # Convert the .VMDK from the OVA to a Virtual Hard Disk (VHD) - Generation 1.
33 ConvertTo-MvmcVirtualHardDisk -SourceLiteralPath $SourceVMDKPath -DestinationLiteralPath $DestinationVHDPath -VhdType FixedHardDisk -VhdFormat Vhd
34  
35 # Create new virtual machine with specified parameters.
36 New-VM -Name $VMName -MemoryStartupBytes 8GB -VHDPath $DestinationVHDPath -Generation -SwitchName $vSwitchName Set-VM -ProcessorCount -Passthru | Start-VM