vmware-cmd - perform virtual machine operations
vmware-cmd [--help | -q | -v]
vmware-cmd -s <conn_option> [-l | -s register <config_file_path> [<datacenter>] [<resource_pool>] | -s unregister <config_file_path> ]
Virtual Machine Operations
vmware-cmd <conn_option> <config_file_path> [answer | connectdevice <device_name> | createsnapshot <name> <description> quiesce [0|1] memory [0|1] | disconnectdevice <device_name> | getconfigfile | getguestinfo <variable> | getproductinfo [product|platform|build|majorversion|minorversion] | getstate | gettoolslastactive | getuptime | hassnapshot | reset [soft|hard] | removesnapshots revertsnapshot | setguestinfo <variable> <value> | start | suspend [soft|hard] ]
vmware-cmd provides an interface to perform operations on a virtual machine. You can retrieve information such as the power state, register and unregister the virtual machine, set configuration variables, and manage snapshots.
The vmware_cmd vSphere CLI command connection options differ from those of most other vSphere CLI commands.
Specifies an ESX/ESXi host or a vCenter Server system.
Specifies a target host if the host specified by -H <host> is a vCenter Server system.
Specifies an alternative port. Default is 443
Name of the user who connects to the target. This user must have privileges to perform the operation.
Password of the user specified by <username>. Required if a user is specified.
Location of a configuration file that specifies connection information.
Name of a credential store file.
Name of a session file that was saved earlier using the vSphere SDK for Perl session/save_session.pl script.
If you specify this option, the system attempts to connect using Microsoft Windows Security Support Provider Interface (SSPI).
Prints a help message for each command-specific and each connection option. Calling the script with no arguments or with --help has the same effect.
Turns on quiet mode with minimal output.
Turns on verbose mode.
The following operations require that you specify the path to the virtual machine configuration file. Choose one of the following formats:
Datastore prefix style:
'[myStorage1] testvms/VM1/VM1.vmx' (Linux) "[myStorage1] testvms\VM1\VM1.vmx" (Windows)
'/vmfs/volumes/mystorage/testvms/VM1/VM1.vmx' (Linux) "/vmfs/volumes/mystorage/testvms/VM1/VM1.vmx" (Windows)
Lists all registered virtual machines.
Registers a virtual machine.
If -H specifies a vCenter Server system, you must specify the datacenter and the resource pool to register the virtual machine in. The default datacenter is ha-datacenter and the default resource pool is Resources.
If -H specifies an ESX/ESXi system, you usually do not specify the resource pool and datacenter. However, if two virtual machines with the same name exist in two resource pools, you must specify the resource pool.
Unregisters a virtual machine.
Prompts the user to answer a question for a virtual machine waiting for user input.
Connects a virtual device to a virtual machine.
Creates a snapshot of the specified virtual machine, providing a name and description for the snapshot.
If the <quiesce> flag is 1 and the virtual machine is powered on when the snapshot is taken, VMware Tools is used to quiesce the file system in the virtual machine. Quiescing a file system is a process of bringing the on-disk data of a physical or virtual computer into a state suitable for backups. This process might include such operations as flushing dirty buffers from the operating system's in-memory cache to disk, or other higher-level application-specific tasks.
If the <memory> flag is 1, a dump of the internal state of the virtual machine is included in the snapshot. Memory snapshots take longer to create.
Disconnects the specified virtual device from the virtual machine.
Returns a string containing the name of the virtual machine configuration file. This command fails if the virtual machine is not connected.
Retrieves the value for a GuestInfo variable. The variable contains the attributes of the guest operating system of a virtual machine. For example, you can run the following command to retrieve the IP address of a virtual machine: vmware-cmd <config_file-path> getguestinfo ip You usually use this command when VMware Technical Support or a VMware Knowledge Base article instruct you to do so.
Returns information about the product, where <prodinfo> is product, platform, build, majorversion (product major version number), or minorversion (product minor version number). If product is specified, the return value is one of the following:
esx -- VMware ESX embeddedESX -- VMware ESXi unknown (unknown product type)
If platform is specified, the return value is one of the following:
win32-x86 -- x86-based Windows system linux-x86 -- x86-based Linux system vmnix-x86 -- x86 ESX/ESXi microkernel
Retrieves the execution state of a virtual machine. The state can be on, off, suspended, or unknown.
Returns an integer indicating how much time has passed, in seconds, since the last heartbeat was detected from the VMware Tools service. This value is initialized to zero when the virtual machine powers on. It stays at zero until the first heartbeat is detected. After the first heartbeat, the value is always greater than zero until the virtual machine is power cycled again. The command can return one of the following:
0 -- VMware Tools are not installed or not running.
1 -- Guest operating system is responding normally.
5 -- Intermittent heartbeat. There might be a problem with the guest operating system.
Returns the uptime (in seconds) of the guest operating system on the virtual machine.
Returns 1 if the virtual machine already has a snapshot. Returns 0 otherwise.
Removes all snapshots belonging to the virtual machine. If no snapshot exists, does nothing.
Shuts down, and then reboots a virtual machine. The powerop_mode can be hard or soft. Default is soft.
Reverts the virtual machine to the current snapshot. If no snapshot exists, does nothing and leaves the virtual machine state unchanged.
Writes a GuestInfo variable into memory. This is an advanced command. You usually use this command when VMware Technical Support or a VMware Knowledge Base article instruct you to do so.
Powers on a previously powered-off virtual machine or resumes a suspended virtual machine.
Shuts down and powers off a virtual machine. The powerop_mode can be hard or soft. Default is soft.
Suspends a virtual machine. The default powerop_mode is soft.
The following examples assume you are specifying connection options, either explicitly or, for example, by specifying the server, user name, and password. Run vmware-cmd --help for a list of common options including connection options.
List all the registered virtual machines:
vmware-cmd <connection_options> -l
Register a virtual machine:
vmware-cmd <connection_options> -s register /vmfs/volumes/storage1/MyVM/MyVM.vmx
Unregister a virtual machine:
vmware-cmd <connection_options> -s unregister /vmfs/volumes/storage1/MyVM/MyVM.vmx
Get the execution state of a virtual machine:
vmware-cmd <connection_options> /vmfs/volumes/storage1/MyVM/MyVM.vmx getstate
Power on a virtual machine with 'soft' power mode (requires VMware Tools):
vmware-cmd <connection_options> /vmfs/volumes/storage1/MyVM/MyVM.vmx start soft
Power on a virtual machine with 'hard' power mode:
vmware-cmd <connection_options> /vmfs/volumes/storage1/MyVM/MyVM.vmx start hard
Set a guest info variable for a virtual machine:
vmware-cmd <connection_options> /vmfs/volumes/storage1/MyVM/MyVM.vmx setguestinfo VarABC 102
Retrieve the value for a guest info variable for a virtual machine:
vmware-cmd <connection_options> /vmfs/volumes/storage1/MyVM/MyVM.vmx getguestinfo VarABC
Get the platform information:
vmware-cmd <connection_options> /vmfs/volumes/storage1/MyVM/MyVM.vmx getproductinfo platform
Get the build information:
vmware-cmd <connection_options> /vmfs/volumes/storage1/MyVM/MyVM.vmx getproductinfo build
Connect a virtual CD/DVD drive to a virtual machine:
vmware-cmd <connection_options> /vmfs/volumes/storage1/MyVM/MyVM.vmx connectdevice "CD/DVD Drive 2"
Disconnect a virtual CD/DVD drive from a virtual machine:
vmware-cmd <connection_options> /vmfs/volumes/storage1/MyVM/MyVM.vmx disconnectdevice "CD/DVD Drive 2"
Retrieve the path to the configuration file for a virtual machine:
vmware-cmd <connection_options> /vmfs/volumes/storage1/MyVM/MyVM.vmx getconfigfile
Retrieve the uptime of a virtual machine's guest OS:
vmware-cmd <connection_options> /vmfs/volumes/storage1/MyVM/MyVM.vmx getuptime
Answer a question for a virtual machine requesting input:
vmware-cmd <connection_options> /vmfs/volumes/storage1/MyVM/MyVM.vmx answer
Retrieve the VMware tools status:
vmware-cmd -U <connection_options> /vmfs/volumes/storage1/MyVM/MyVM.vmx gettoolslastactive
You can perform any of the datacenter operations on a vCenter Server system
by specifying the vCenterServer system using the
-H option and the ESX/ESXi host using the
--vihost | -h option.
To register a virtual machine on a vCenter Server system, you have to specify the
datacenter and resource pool name. For example:
Register a virtual machine.
vmware-cmd -U <myuser> -P <mypassword> -H VCServerABC --vihost ESXHost -s register /vmfs/volumes/storage1/MyVM/MyVM.vmx DatacenterA PoolC
Get the execution state of a virtual machine.
vmware-cmd -U <myuser> -P <mypassword> -H VCServerABC -h ESXHost /vmfs/volumes/storage1/MyVM/MyVM.vmx getstate
Get the product information.
vmware-cmd -U <myuser> -P <mypassword> -H VCServerABC --vihost ESXHost /vmfs/volumes/storage1/MyVM/MyVM.vmx getproductinfo product
Determine if the virtual machine has snapshot.
vmware-cmd -U <myuser> -P <mypassword> -H VCServerABC -h ESXHost /vmfs/volumes/storage1/MyVM/MyVM.vmx hassnapshot
Create a snapshot.
vmware-cmd -U <myuser> -P <mypassword> -H VCServerABC -h ESXHost /vmfs/volumes/storage1/MyVM/MyVM.vmx createsnapshot <name> <description> <quiesce> <memory>
Revert the virtual machine to the last snapshot.
vmware-cmd -U <myuser> -P <mypassword> -H VCServerABC -h ESXHost /vmfs/volumes/storage1/MyVM/MyVM.vmx revertsnapshot
Remove all the snapshots of virtual machine
vmware-cmd -U <myuser> -P <mypassword> -H VCServerABC -h ESXHost /vmfs/volumes/storage1/MyVM/MyVM.vmx removesnapshots