Monday, 22 February 2016

Converting a VMware Virtual Machine to Hyper-V

Occasionally the need arises to convert a VMware virtual machine (vmdk) to work in a Hyper-V environment (vhdx).  There are a number of third-party tools available to accomplish this task, some better than others.  However, wherever possible, I like to use tools built into an Operating System, or made directly by the same company.  Enter Microsoft Virtual Machine Converter.

This tool enables the direct conversion of a vmdk file with PowerShell, and can be downloaded from here: https://www.microsoft.com/en-us/download/details.aspx?id=42497

Download and install to the default location.  Then open a PowerShell window with elevated privilages, and run the following command:
     Import-Module 'C:\Program Files\Microsoft Virtual Machine Converter\MvmcCmdlet.psd1

This cmdlet contains a number of commands that can be used to perform various conversion tasks.  However the simplest is "ConvertTo-MvmcVirtualHardDisk".

Remaining in the elevated PowerShell window, enter the following command (obvioulsy you will need to change both the "SourceLiteralPath" (source) and "Destination" arguments:
     ConvertTo-MvmcVirtualHardDisk -SourceLiteralPath C:\TEMP\Disk1.vmdk -VhdType DynamicHardDisk -VhdFormat vhdx -destination C:\Temp\Disk1

That's it.  Wait for the command to complete, and you will have a fully functioning vhdx file you can use with your shiny new Hyper-V virtual machine.