Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

VMDK to VHDX PDQ

Posted on June 26, 2015June 26, 2015

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.

Manage and Report Active Directory, Exchange and Microsoft 365 with
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.

 


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

2 thoughts on “VMDK to VHDX PDQ”

  1. Savas says:
    August 21, 2015 at 8:01 am

    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?

    1. Jeffery Hicks says:
      August 21, 2015 at 8:29 am

      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.

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d