Skip to main content
Pure Technical Services

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

Currently viewing public documentation. Please login to access the full scope of documentation.

This KB has been migrated to the new Knowledge Base and can be found here: https://kb.purestorage.com/csm?id=kb...icle=KB0014040.

Please update your bookmarks, if you have any questions please ping us at knowledge-feedback@purestorage.com.

Problem

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.

Solution

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

Script Requirements

  • 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:

New-Object : Exception calling ".ctor" with "3" argument(s): "End of Central 
Directory record could not be found."
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Arch
ive\Microsoft.PowerShell.Archive.psm1:933 char:23
+ ... ipArchive = New-Object -TypeName System.IO.Compression.ZipArchive -Ar ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvoca 
   tionException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power 
   Shell.Commands.NewObjectCommand

Script Source 

<# 
#  Name: New-ActiveClusterMediatorVM.ps1
#  Version: 0.5
#  Purpose: Convert VMware OVA to Hyper-V VHD.
#>
#Requires -Version 5
Clear-Host

# Set default variables.
$ACMDirectory = "D:\ACM"
$VMName = "AC-MediatorTest"
$HyperVHost = "localhost"
$OVAName = "<NAME>.ova"
$SourceOVAPath = "$ACMDirectory\$OVAName"
$DestinationVHDPath = "$ACMDirectory\$VMName.vhd"
$vSwitchName = "vSwitch"

# Import the Microsoft VM Converter Powershell Module.
# Install from https://www.microsoft.com/en-us/download/details.aspx?id=42497
Import-Module "C:\Program Files\Microsoft Virtual Machine Converter\MvmcCmdlet.psd1"
Import-Module -Name 7Zip4Powershell

# Unzip the <Name>.ova file to specified directory. An OVA is just a ZIP (TAR) file containing contents. 
Copy-Item -Path $SourceOVAPath -Destination "$ACMDirectory\$VMName.zip"
Expand-7Zip -ArchiveFileName "$SourceOVAPath" -TargetPath "$ACMDirectory\$VMName"

# Find VMDK to convert to VHD.
$VMDKName = (Get-ChildItem -Path "$ACMDirectory\$VMName" -Filter *.vmdk).Name
$SourceVMDKPath = "$ACMDirectory\$VMName\$VMDKName"

# Convert the .VMDK from the OVA to a Virtual Hard Disk (VHD) - Generation 1.
# To understand Gen1 vs Gen2 read https://technet.microsoft.com/en-us/library/dn440675%28v=sc.12%29.aspx?f=255&MSPPError=-2147217396
ConvertTo-MvmcVirtualHardDisk -SourceLiteralPath $SourceVMDKPath -DestinationLiteralPath $DestinationVHDPath -VhdType FixedHardDisk -VhdFormat Vhd

# Create new virtual machine with specified parameters.
New-VM -Name $VMName -MemoryStartupBytes 8GB -VHDPath $DestinationVHDPath -Generation 1 -SwitchName $vSwitchName | Set-VM -ProcessorCount 2 -Passthru | Start-VM