Automating VMware Workstation with the vmrun Command: From Manual Management to Pro

VMware tutorial - IT technology blog
VMware tutorial - IT technology blog

How many minutes do you waste clicking to open virtual machines every day?

If you only use one VM to test software, clicking the Power button in the VMware interface is no big deal. But imagine having a network lab with 5-7 machines: Domain Controller, Client, Firewall, and Web Server. Every morning, waiting for each machine to load before clicking the next one is a real productivity killer.

Previously, when managing lab clusters on old servers, I often had to work via SSH. That’s when I realized the value of vmrun. This tool helps start machines quickly and allows for full automation scripts. You can power on machines in a specific order, create snapshots before testing, or copy files to a VM without opening the console window.

Where vmrun fits into your system

vmrun is a command-line interface (CLI) utility included when you install VMware Workstation or Fusion. It allows you to control the Hypervisor directly from the terminal. On Windows, you can usually find the executable at:

C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe

For convenience, you should add this path to your Environment Variables (PATH). Once set up, you can simply type vmrun anywhere instead of typing the long file path.

Quick Check:

Open CMD or PowerShell and type:

vmrun

If the screen displays a list of help parameters, you’re ready to go.

Essential VM Control Commands

The basic syntax for vmrun is: vmrun -T [platform] [command] "path_to_vmx" [options]. For VMware Workstation, the platform parameter is always ws.

1. Starting a Virtual Machine (Start)

You can choose to open the VM window or run it in the background to save resources.

# Run with GUI
vmrun -T ws start "D:\VMs\Ubuntu\Ubuntu.vmx"

# Run in the background (Headless mode - very lightweight)
vmrun -T ws start "D:\VMs\Ubuntu\Ubuntu.vmx" nogui

The nogui mode is very useful when you only need to SSH into the VM. It significantly reduces the load on your graphics card since it doesn’t have to render the console window.

2. Stopping and Restarting (Stop & Reset)

Instead of an abrupt virtual “unplug,” use the soft parameter to request the operating system to shut down safely.

# Safe shutdown (Requires VMware Tools)
vmrun -T ws stop "D:\VMs\Ubuntu\Ubuntu.vmx" soft

# Restart the virtual machine
vmrun -T ws reset "D:\VMs\Ubuntu\Ubuntu.vmx" soft

3. Checking the list of running machines

To see how many VMs are currently consuming system RAM, use the command:

vmrun list

Managing Snapshots in Seconds

Snapshots are “insurance” for IT pros when experimenting with systems. Instead of clicking through multiple menus, vmrun handles snapshots decisively.

Create a quick snapshot:

vmrun -T ws snapshot "D:\VMs\Win10\Win10.vmx" "Backup_Before_Installing_App"

Reverting state (Revert):

If an installation goes wrong, I only need one command to bring the machine back to its original clean state:

vmrun -T ws revertToSnapshot "D:\VMs\Win10\Win10.vmx" "Backup_Before_Installing_App"

Interacting Directly with the Guest OS

This is the most valuable feature of vmrun. You can execute commands inside the VM right from the host machine. The mandatory requirement is that the VM must be running and have VMware Tools installed.

1. Running a program inside the VM

Example: Opening Notepad on a Windows VM from the host’s CMD:

vmrun -T ws -gu [User] -gp [Pass] runProgramInGuest "D:\VMs\Win10.vmx" "C:\Windows\notepad.exe"

2. High-speed file copying

I often use this command to push configuration files to multiple VMs at once:

vmrun -T ws -gu admin -gp 123456 copyFileFromHostToGuest "D:\VMs\Win10.vmx" "C:\lab\config.txt" "C:\Users\admin\Desktop\config.txt"

Practical Script: Start an Entire Lab with One Click

To optimize your workflow, create a .bat file to power on your machines in order. For example: Start the Domain Controller first, wait 30 seconds, then start the Client machines.

@echo off
SET VMRUN="C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe"

echo Starting Domain Controller...
%VMRUN% -T ws start "D:\Lab\DC01\DC01.vmx" nogui

timeout /t 30

echo Starting Web Server...
%VMRUN% -T ws start "D:\Lab\WebServer\Web.vmx" nogui

echo Starting Windows Client...
%VMRUN% -T ws start "D:\Lab\Win10\Win10.vmx"

echo Entire Lab is ready!
pause

Pro-tips and Considerations

  • Double Quotes: Always put the VMX file path in double quotes " ". If a folder name contains spaces and you miss these quotes, the command will definitely fail.
  • VMware Tools: Commands like copyFile or soft stop won’t work without Tools. Ensure Tools is always in a ‘Running’ state.
  • Administrator Privileges: Some deep system operations require you to run CMD with Administrator privileges.
  • Resource Control: Don’t start too many VMs simultaneously in a script. Use the timeout command to stagger them and avoid disk congestion (I/O Wait).

Mastering vmrun gives you much more flexibility in managing virtual infrastructure than using the traditional interface. This is the first step toward integrating VMware into complex automation or CI/CD pipelines. Try applying it to your lab today!

Share: