Editing a .VMCX file
In Windows Server 2016 we moved from using .XML for our virtual machine configuration files to using a binary format – that we call .VMCX.
There are many benefits to this – but one of the downsides is that it is no longer possible to easily edit a virtual machine configuration file that is not registered with Hyper-V. Fortunately – we provide all the APIs you need to do this without editing the file directly.
This code sample takes a virtual machine configuration file – that is not registered with Hyper-V. It then:
- Loads the virtual machine into memory – without actually importing it into Hyper-V
- Changes some settings on the virtual machine
- Exports this changed virtual machine to a new .VMCX file
Using this method you can make any changes you need to a .VMCX file without actually having to import the virtual machine. The key piece of information here is that when you perform a traditional import of a virtual machine you use ImportSystemDefinition to create a planned virtual machine (in memory copy) which you then realized to complete the import operation. But if you do not want to import the virtual machine – but just want to edit it – you can modify the planned virtual machine and pass it into ExportSystemDefinition to create a new configuration file.