This article provides a comparison of virtual machine related tasks using different command line methods.
VMware vSphere ESXi 6.5.x
VMware vSphere ESXi 6.7.x
VMware vSphere ESXi 7.x
VMware vSphere ESXi 8.x
VMware vSphere ESXi 9.x
VMware vSphere PowerCLI
In these examples:
vcenter
is the vCenter Server hostnameesxhost
is the ESX/ESXi hostnamedatastore
is the display name of the datastorepath_to_vmx_on_datastore
is the path to the virtual machine's vmx file on the datastorevm_name
is the display name of a virtual machinepath_to_vmx_file
is the full path to the virtual machine's vmx filesnapshot_name
is the name of the virtual machine snapshotguest_admin_user
is a user account with administrative access within a virtual machine's guest OSguest_admin_password
is the password for the account guest_admin_user
Action | PowerCLI |
Register a VM | New-VM –vmfilepath “[datastore] path_to_vmx_on_datastore” –vmhost esxhost |
Unregister a VM | Remove-VM vm_name |
Delete a VM | Remove-VM vm_name -deletepermanently |
List VMs on a host | Get-VM –location esxhost |
Determine if a VM has a snapshot | Get-VM –name vm_name | Get-Snapshot |
Take a snapshot of a VM | Get-VM –name vm_name | New-Snapshot –name snapshot_name |
Remove a snapshot of a VM | Get-VM –name vm_name | Get-Snapshot –name snapshot_name | Remove-Snapshot |
Get the current power state of a VM | Get-VM –name vm_name |
Get the uptime for a VM | Get-Stat -entity vm_name -stat sys.uptime.latest -MaxSamples 1 |
Power on a VM | Start-VM –vm vm_name |
Power off a VM | Shutdown-VMGuest –vm vm_name |
Power off a VM | Stop-VM –vm vm_name |
Reboot a VM | Restart-VMGuest –vm vm_name |
Reset a VM | Restart-VM –vm vm_name |
Upgrade VMware Tools in a VM | Update-Tools –vm vm_name |
Display the IP address of a VM | Get-VMGuestNetworkInterface –vm vm_name -guestuser guest_admin_user -guestpassword guest_admin_password |
Action | ESXi |
Register a VM |
vim-cmd solo/registervm path_to_vmx_file vim-cmd /solo/register path_to_vmx_file |
Unregister a VM | vim-cmd vmsvc/unregister vmID |
Delete a VM | vim-cmd vmsvc/destroy vmID |
List VMs with vmIDs | vim-cmd vmsvc/getallvms |
List snapshots of VM | vim-cmd vmsvc/get.snapshot vmid |
Take a snapshot of a VM | vim-cmd vmsvc/snapshot.create vmID snapshot_name snapshot_description |
Remove a snapshot of a VM | vim-cmd vmsvc/snapshot.remove vmID |
Get the power state of a VM | vim-cmd vmsvc/power.getstate vmID |
Get the uptime for a VM | vim-cmd vmsvc/get.summary vmID |grep uptimeSeconds |
Power on a VM | vim-cmd vmsvc/power.on vmID |
Shutdown the VM guest OS | vim-cmd vmsvc/power.shutdown vmID |
Power off a VM | vim-cmd vmsvc/power.off vmID |
Reboot the VM guest OS | vim-cmd vmsvc/power.reboot vmID |
Reset a VM | vim-cmd vmsvc/power.reset vmID |
Upgrade VMware Tools of a VM | vim-cmd vmsvc/tools.upgrade vmID |
Display the IP address of a VM | vim-cmd vmsvc/get.guest vmID |grep -m 1 "ipAddress = \" |