I have a very old VMware ESXi server that has outlived its useful life. The hardware is at least 5 years old and my VMware license has expired. I can still bring up the server and see the virtual machines, but that's about it. I still keep the box so I can run the PowerCLI cmdlets, at least in a limited fashion. However, there are a few virtual machines that I need to get at so I can move some applications and data to another Hyper-V virtual machine. Since I can't get the VMware virtual machine running, I can at least convert the disk to a VHDX and bring it up in a new Hyper-V virtual machine.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
I already have PowerCLI 6.0 and the Hyper-V cmdlets installed on my computer. My initial thought was to use the free Microsoft Virtual Machine Converter which you can download. But I ran into a number of issues using the GUI, primarily because not everything is in the same domain. But that doesn't really matter because I didn't really want to migrate the complete virtual machine, I just needed to bring up the old VM temporarily so I could migrate things off. Fortunately, there are a set of cmdlets that ship with Microsoft's converter. Here's what I did.
First, I needed to connect to my ESXi box using the PowerCLI cmdlets.
add-pssnapin vmware.vimautomation.core
Connect-VIServer -Server esxi.globomantics.local -user root
I need to get the disk files for a given virtual machine. One benefit of PowerCLI is that you can easily browse the datastore files.
$path = 'vmstore:\ha-datacenter\datastore1\globomantics mail\Win2K8R2*.vmdk'
I'll need all of these files. But first I need to be able to access them from the file system. Fortunately, PowerCLI has a handly cmdlet for copying items from a datastore to the file system.
Copy-DatastoreItem -item $path -Destination F:\ -PassThru
Once the files are copied I can begin the conversion. However, the Microsoft virtual machine converter cmdlets aren't installed in an expected location so I'll have to manually import them.
Import-Module 'C:\Program Files\Microsoft Virtual Machine Converter\mvmccmdlet.psd1'
Once imported, I can use ConvertTo-MvmcVirtualHardDisk.
$paramHash = @{ SourceLiteralPath = 'F:\Win2K8R2.vmdk' DestinationLiteralPath = 'F:\Converted\GloboMail.vhdx' VhdType = 'DynamicHardDisk' VhdFormat = 'Vhdx' } ConvertTo-MvmcVirtualHardDisk @paramHash
The conversion took about 20 minutes for a 40GB file. The converted file was 30GB for a dynamic hard disk. With the conversion complete, it is pretty easy to fire up a new Hyper-V virtual machine.
Hyper-V\New-VM -Name CHI-EX01 -VHDPath $paramHash.DestinationLiteralPath -SwitchName "Work Network" -MemoryStartupBytes 1GB -Generation 1 |
Hyper-V\Set-VM -DynamicMemory -ProcessorCount 2 -MemoryMinimumBytes 1GB
Hyper-V\Start-VM chi-ex01
You'll notice that I am using a complete path for the New-VM cmdlet. That's because in my session I have both PowerCLI and Hyper-V cmdlets and they both have a New-VM cmdlet. Normally I wouldn't have both running in the same session but since I do, I need to explicitly tell PowerShell which cmdlet to use.
And that's about it. Once running I uninstalled the VMware Tools, installed the Hyper-V Integration Toolkit and let Windows detect everything else. This would require me re-activating Windows, but I'm hoping to migrate everything I need before that becomes an issue.
Hi Jeffery
great walk-through! I wonder how it could be done in the other direction. If someone wanted to convert a VHDX into a VMDK for example, would these powershell libraries have options for that scenario?
I think the PowerShell commands I used only work from VMDX to VHDX. There may be PowerShell commands to go the other way, but I don’t know of any off the top of my head.