Performing common virtual machine-related tasks with command-line utilities
search cancel

Performing common virtual machine-related tasks with command-line utilities

book

Article ID: 308360

calendar_today

Updated On:

Products

VMware vCenter Server VMware vSphere ESXi

Issue/Introduction

This article provides a side-by-side comparison of performing virtual machine-related tasks using different utilities and command line methods.

Environment

VMware vSphere ESXi . xxx
VMware vSphere PowerCLI . xxx 

Resolution

In these examples:

  • vcenter is your vCenter Server hostname
  • esxhost is your ESX/ESXi hostname
  • datastore is the display name of your datastore
  • path_to_vmx_on_datastore is the path to the virtual machine's vmx file relative to the datastore on which it resides
  • vm_name is the display name of a virtual machine
  • path_to_vmx_file is the full path to a virtual machine's vmx file
  • snapshot_name is the name given to a virtual machine snapshot
  • guest_admin_user is a user account with administrative access within a virtual machine's guest OS
  • guest_admin_password is the password for the account noted by guest_admin_user

 

  PowerCLI ESXi
Register a VM New-VM –vmfilepath “[datastore] path_to_vmx_on_datastore” –vmhost esxhost vim-cmd solo/registervm path_to_vmx_file
Unregister a VM Remove-VM vm_name vim-cmd vmsvc/unregister vmid 
Delete a VM Remove-VM vm_name -deletepermanently vim-cmd vmsvc/destroy vmid
Get a listing of VMs on a host Get-VM –location esxhost 1. esxcli vm process list
2. vim-cmd vmsvc/getallvms
Determine if a VM has a snapshot Get-VM –name vm_name | Get-Snapshot vim-cmd vmsvc/get.snapshot vmid
Take a snapshot of a VM Get-VM –name vm_name | New-Snapshot –name snapshot_name vim-cmd vmsvc/snapshot.create vmid snapshot_name
Remove a snapshot of a VM Get-VM –name vm_name | Get-Snapshot –name snapshot_name | Remove-Snapshot vim-cmd vmsvc/snapshot.remove vmid
Get the current power state of a VM Get-VM –name vm_name vim-cmd vmsvc/power.getstate vmid
Get the uptime for a VM Get-Stat -entity vm_name -stat sys.uptime.latest -MaxSamples 1 vim-cmd vmsvc/get.summary vmid |grep uptimeSeconds
Power on a VM Start-VM –vm vm_name vim-cmd vmsvc/power.on vmid
Shutdown a VM Shutdown-VMGuest –vm vm_name vim-cmd vmsvc/power.shutdown vmid
Power off a VM Stop-VM –vm vm_name 1. esxcli vm process kill –w world_id
2. vim-cmd vmsvc/power.off vmid
Reboot a VM Restart-VMGuest –vm vm_name vim-cmd vmsvc/power.reboot vmid
Reset a VM Restart-VM –vm vm_name vim-cmd vmsvc/power.reset vmid
Upgrade VMware Tools in a VM Update-Tools –vm vm_name vim-cmd vmsvc/tools.upgrade vmid
Display the IP address of a VM Get-VMGuestNetworkInterface –vm vm_name -guestuser guest_admin_user -guestpassword guest_admin_password vim-cmd vmsvc/get.guest vmid |grep -m 1 "ipAddress = \""