Using vmrun to immediately update displayName of virtual machine in VMWare workstation gui

1.4k Views Asked by At

I am scripting VMWare Workstation (8.0.2) from Windows Powershell on Windows 7. I am trying to clone a template virtual machine and make several instances of it, each with a different display name. This is so I can then use the GUI to easily identify and control the machines after this has completed.

By default, vmrun will make the name of the cloned machine "Copy of (old machine name)". I'd like to change this name, so I can easily identify the machine from the workstation GUI.

The code I'm using is

& vmrun clone "path to master vm.vmx" "path to new vm.vmx" linked snapshot_01
# attempting to change the display name here results in an error "vm not started"
& vmrun start "path to new vm.vmx" gui
& vmrun writeVariable "path to new vm.vmx" runtimeConfig displayName "new display name"

Unfortunately, this code does not update the VMWare workstation GUI. Using the "readVariable" command I can read out the new value.

I'm considering writing some Powershell to update the .vmx file directly, but just feel there has to be a better way.

1

There are 1 best solutions below

0
On

Yes, i have done this with Powershell. Easy Task.

(get-content $CloneVMX) | foreach-object {$_ -replace 'displayName = "Clone of Master2012"', $Displayname } | set-content $CloneVMX

Where $clonevmx is the Path to your .vmx file It is Just Reading and Replacing, i do it right after creting the linked clone.

see more at BRS2GO