Let’s Work Together

Partner with you to deliver responsive and cost-effective IT & Support solutions
Partner with you
Attitude to Serve
These are the reasons why AionSolution is your vendor when you are seeking someone to support your IT in your office.
+852 2636 6177

Recover vmx from log file

 Recover vmx from log file

On the VMware community forums, Eric Tung has devised a little jewel of code that automates recreating a vmx file from a recent vmware.log file.

This is possible as on every boot of a virtual machine, the vmware.log gets a copy from your virtual hardware settings written out into the vmware.log logfile along with some extra information such as the date and time this VM was run. The script extracts the relevant part for you and eliminates the risk of making a typo while doing this by hand. It is written in perl, just a few lines long and shows the true power of what a bit of perl can do for you 🙂

vmxRecover.pl code

use strict;
use warnings;  

if ($#ARGV != 0) {
   print "Recovers .vmx files from .log files. Usage:\n";
   print "$0 logfile > vmxfile\n\n";

while (<>) {
   # Scan until we reach the config section
   if (/: vmx\| DICT --- CONFIGURATION/) { last; }

while (<>) {
   if (/: vmx\| DICT --- \S/) { last; } # Keep going until the next section
   s/^.*: vmx\| DICT\s*//;    # Strip off the leading timestamp and other stuff
   s/\r//;                    # Get rid of any \r's that may have somehow snuck in
   s/([^=]*=) (.*)/$1 "$2"/;  # Quote the value


Say you want to recreate a the virtual hardware configuration for a VMware virtual machine “Windows XP.vmx” then you’d call it like this:

vmxRecover.pl vmware.log > "Windows XP.vmx"

Another way to do it.

Rebuilding the virtual machine’s .vmx file from vmware.log


You may want to rebuild the .vmx file of a virtual machine and recover its contents if the .vmx is missing or has lost its configuration.

This article provides a shell script that rebuilds the .vmx file from the vmware.log file.


To rebuild the virtual machine’s .vmx file using a shell script which parses the information from the vmware.log file:


  • VMware does not guarantee that this script will recover every .vmx file. This is only an option to try if the operation becomes necessary. For example, if the virtual machine configuration is changed after the last power on, then that information is not logged in the vmware.log and the .vmx may not be accurate.
  • Ensure that you run the commands or the script from the virtual machine working directory. To determine the working directory, right-click the virtual machine and click Edit Settings, then click Options > Virtual Machine Working Location.
  1. Create a new file using a text editor. Name it, for example, vmxrebuild.sh.

    Note: For information on using a text editor, see Editing files on an ESX host using vi or nano (1020302).

  2. Copy and paste this script to the file:

    VMXFILENAME=$(sed -n 's/^.*Config file: .*\/\(.\+\)$/\1/p' vmware.log)
    echo -e "#\041/usr/bin/vmware" > ${VMXFILENAME}
    echo '.encoding = "UTF-8"' >> ${VMXFILENAME}
    sed -n '/DICT --- CONFIGURATION/,/DICT ---/ s/^.*DICT \+\(.\+\) = \(.\+\)$/\1 = "\2"/p' vmware.log >> ${VMXFILENAME}

  3. Save the file, ensuring that it has an .sh extension.
  4. Run this command to give execute privileges to the file:

    chmod +x filename

    Where filename is the name of the saved shell script file.

  5. If uuid.location has changed due to operations such as cloning or Storage vMotion, run this command to get the new UUID:

    NEWUUID=$(sed -n "s/^.*UUID: Writing uuid.location value: '\(.\+\)'.*$/\1/p" vmware.log)

    Note: Whenever possible, use the latest vmware.log file.

  6. Run this command to replace the old UUID in the .vmx file with the new one:

    if [ "${NEWUUID}" ] then sed -i "s/uuid.location = .*$/uuid.location = \"${NEWUUID}\"/" ${VMXFILENAME} fi

  7. To run the script: