Created
July 31, 2011 22:23
-
-
Save thbishop/1117286 to your computer and use it in GitHub Desktop.
How to programmatically delete a VM from VMware Fusion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The primary fusion app must be closed for this to work. | |
# It appears that the primary fusion app holds the plist data in memory | |
# and will write the changes to disk when it closes | |
# (including overwriting any changes made by another app). | |
# You should not have any issues if you execute this when there are | |
# headless VMs running (i.e. 'vmrun start $path_to_vmx nogui'). | |
require 'cfpropertylist' | |
plist_file_path = '/Users/tbishop/Library/Preferences/com.vmware.fusion.plist' | |
existing_plist = CFPropertyList::List.new(:file => plist_file_path) | |
data = CFPropertyList.native_types(existing_plist.value) | |
vm_name = 'my_test' | |
vm_path = '' | |
# get the vm path for later | |
data['VMFavoritesListDefaults2'].each do |vm| | |
if vm['name'] == vm_name | |
vm_path = vm['path'] | |
break | |
end | |
end | |
# this appears to be the list of VM console windows to open when fusion starts | |
# if there are no VM console windows to open, this key doesn't exist | |
if data.has_key?('PLRestartDocumentPaths') | |
data['PLRestartDocumentPaths'].delete_if { |path| path == vm_path } | |
end | |
data['VMFavoritesListDefaults2'].delete_if { |vm| vm['name'] == vm_name} | |
# save the updated data | |
new_list = CFPropertyList::List.new | |
new_list.value = CFPropertyList.guess(data) | |
new_list.save plist_file_path, CFPropertyList::List::FORMAT_BINARY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I *think* this requires the primary fusion app to be closed. | |
# This appears to only cleanup the file system and not the plist data. | |
/Library/Application\ Support/VMware\ Fusion/vmrun -T fusion deleteVM /vm/my_test.vmwarevm/my_test.vmx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In my testing deleteVM does not work while Fusion is running.