Home

VMware Commands

Comprehensive ESXi and PowerCLI Command Reference

VMware Command Line Tools

VMware provides powerful command-line interfaces for managing ESXi hosts and vSphere infrastructure. This comprehensive reference covers ESXCLI commands for ESXi management, PowerCLI for vSphere automation, and additional command-line tools for advanced administration.

Master these commands to automate tasks, troubleshoot issues, and manage your VMware infrastructure efficiently from the command line.

ESXCLI Commands

ESXCLI is the primary command-line interface for ESXi host management, providing access to system configuration, hardware management, and troubleshooting capabilities.

System Information

# Get ESXi version and build information
esxcli system version get

# Display system hostname and domain
esxcli system hostname get

# Show system UUID
esxcli system uuid get

# Display ESXi uptime
esxcli system stats uptime get

# View welcome message and MOTD
esxcli system welcomemsg get

Network Management

# List all network interfaces
esxcli network nic list

# Show detailed NIC information
esxcli network nic get -n vmnic0

# Display network statistics for interface
esxcli network nic stats get -n vmnic0

# List all virtual switches
esxcli network vswitch standard list

# Add a virtual switch
esxcli network vswitch standard add -v vSwitch1

# Remove a virtual switch
esxcli network vswitch standard remove -v vSwitch1

# Add uplink to vSwitch
esxcli network vswitch standard uplink add -v vSwitch0 -u vmnic1

# Create a port group
esxcli network vswitch standard portgroup add -p "Production VMs" -v vSwitch0

# Set VLAN on port group
esxcli network vswitch standard portgroup set -p "Production VMs" -v 100

# Display IP interface configuration
esxcli network ip interface ipv4 get

# Set management network IP address
esxcli network ip interface ipv4 set -i vmk0 -t static -I 192.168.1.10 -N 255.255.255.0 -g 192.168.1.1

# Configure DNS servers
esxcli network ip dns server add -s 8.8.8.8
esxcli network ip dns server add -s 8.8.4.4

# List network connections
esxcli network ip connection list

# Display routing table
esxcli network ip route ipv4 list

# Add static route
esxcli network ip route ipv4 add -n 10.0.0.0/8 -g 192.168.1.1

Storage Management

# List all storage adapters
esxcli storage core adapter list

# Show storage adapter details
esxcli storage core adapter get -A vmhba0

# List all storage devices
esxcli storage core device list

# Display device details
esxcli storage core device get -d naa.600508b1001c1234567890abcdef

# List all storage paths
esxcli storage core path list

# Show multipathing configuration
esxcli storage nmp device list

# Set multipathing policy
esxcli storage nmp device set -d naa.600508b1001c1234 -P VMW_PSP_RR

# List VMFS volumes
esxcli storage vmfs extent list

# Create VMFS datastore
esxcli storage vmfs create -d naa.600508b1001c1234 -n "Datastore01"

# List NFS mounts
esxcli storage nfs list

# Mount NFS datastore
esxcli storage nfs add -H 192.168.1.100 -s /nfs/datastore1 -v nfs-datastore1

# Unmount NFS datastore
esxcli storage nfs remove -v nfs-datastore1

# Rescan storage adapters
esxcli storage core adapter rescan --all

# Rescan VMFS volumes
esxcli storage vmfs snapshot list

Virtual Machine Management

# List all VMs and their IDs
vim-cmd vmsvc/getallvms

# Power on a VM
vim-cmd vmsvc/power.on [vmid]

# Power off a VM
vim-cmd vmsvc/power.off [vmid]

# Reset a VM
vim-cmd vmsvc/power.reset [vmid]

# Shutdown guest OS (VMware Tools required)
vim-cmd vmsvc/power.shutdown [vmid]

# Reboot guest OS (VMware Tools required)
vim-cmd vmsvc/power.reboot [vmid]

# Get VM power state
vim-cmd vmsvc/power.getstate [vmid]

# Create VM snapshot
vim-cmd vmsvc/snapshot.create [vmid] "SnapshotName" "Description" 0 0

# List VM snapshots
vim-cmd vmsvc/snapshot.get [vmid]

# Remove VM snapshot
vim-cmd vmsvc/snapshot.remove [vmid] [snapshotId]

# Revert to snapshot
vim-cmd vmsvc/snapshot.revert [vmid] [snapshotId]

# Get VM configuration
vim-cmd vmsvc/get.config [vmid]

# Unregister VM
vim-cmd vmsvc/unregister [vmid]

# Register VM
vim-cmd solo/registervm /vmfs/volumes/datastore1/vm/vm.vmx

Host Services Management

# List all services
services.sh status

# Start SSH service
services.sh start TSM-SSH
# Or using vim-cmd
vim-cmd hostsvc/enable_ssh
vim-cmd hostsvc/start_ssh

# Stop SSH service
services.sh stop TSM-SSH
# Or using vim-cmd
vim-cmd hostsvc/stop_ssh
vim-cmd hostsvc/disable_ssh

# Start ESXi Shell
vim-cmd hostsvc/enable_esx_shell
vim-cmd hostsvc/start_esx_shell

# Stop ESXi Shell
vim-cmd hostsvc/stop_esx_shell
vim-cmd hostsvc/disable_esx_shell

# Restart management agents
services.sh restart

# List running services
chkconfig --list

Firewall Management

# List firewall rules
esxcli network firewall ruleset list

# Enable firewall rule
esxcli network firewall ruleset set -r sshServer -e true

# Disable firewall rule
esxcli network firewall ruleset set -r sshServer -e false

# Allow IP through firewall rule
esxcli network firewall ruleset allowedip add -r sshServer -i 192.168.1.0/24

# Show allowed IPs for rule
esxcli network firewall ruleset allowedip list -r sshServer

# Enable firewall
esxcli network firewall set -e true

# Disable firewall (not recommended)
esxcli network firewall set -e false

# Refresh firewall rules
esxcli network firewall refresh

Software and VIB Management

# List installed VIBs (VMware Installation Bundles)
esxcli software vib list

# Install VIB
esxcli software vib install -v /vmfs/volumes/datastore1/vib-package.vib

# Install VIB from URL
esxcli software vib install -d https://example.com/package.zip

# Remove VIB
esxcli software vib remove -n vib-name

# Update VIB
esxcli software vib update -v /vmfs/volumes/datastore1/update.vib

# List available profiles
esxcli software sources profile list -d /vmfs/volumes/datastore1/ESXi.iso

# Install offline bundle
esxcli software profile install -d /vmfs/volumes/datastore1/offline-bundle.zip -p ESXi-7.0-Profile

# Update ESXi from depot
esxcli software profile update -d https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml -p ESXi-7.0-Latest

# Get acceptance level
esxcli software acceptance get

# Set acceptance level
esxcli software acceptance set --level CommunitySupported

Hardware Management

# List PCI devices
esxcli hardware pci list

# Display memory information
esxcli hardware memory get

# Show CPU information
esxcli hardware cpu list

# Display platform information
esxcli hardware platform get

# Show IPMI information
esxcli hardware ipmi sdr list

# Monitor hardware sensors
esxcli hardware ipmi sel list

# Get boot device information
esxcli hardware bootdevice list

Performance Monitoring

# Monitor real-time performance (like top)
esxtop

# Batch mode for scripting
esxtop -b > esxtop-output.csv

# Monitor specific VM
esxtop -v [vmid]

# Display load average
esxcli system stats uptime get

# View memory statistics
esxcli system stats memory get

# Show swap information
esxcli sched swap system get

PowerCLI Commands

PowerCLI is VMware's PowerShell-based command-line interface for vSphere automation and management. It provides comprehensive cmdlets for managing all aspects of your VMware infrastructure.

Connection Management

# Connect to vCenter Server
Connect-VIServer -Server vcenter.example.com

# Connect with credentials
Connect-VIServer -Server vcenter.example.com -User admin -Password pass

# Connect to multiple vCenters
Connect-VIServer -Server vcenter1.example.com,vcenter2.example.com

# Disconnect from vCenter
Disconnect-VIServer -Server vcenter.example.com -Confirm:$false

# Disconnect from all servers
Disconnect-VIServer -Server * -Confirm:$false

# Get current connections
$global:DefaultVIServers

Virtual Machine Management

# List all VMs
Get-VM

# Get specific VM
Get-VM -Name "WebServer01"

# Get VMs matching pattern
Get-VM -Name "Web*"

# Power on VM
Start-VM -VM "WebServer01"

# Power off VM
Stop-VM -VM "WebServer01"

# Shutdown guest OS
Stop-VMGuest -VM "WebServer01"

# Restart VM
Restart-VM -VM "WebServer01"

# Restart guest OS
Restart-VMGuest -VM "WebServer01"

# Suspend VM
Suspend-VM -VM "WebServer01"

# Create new VM
New-VM -Name "NewVM" -VMHost esxi01.example.com -Datastore datastore1 -DiskGB 40 -MemoryGB 4 -NumCpu 2

# Remove VM
Remove-VM -VM "OldVM" -DeletePermanently -Confirm:$false

# Clone VM
New-VM -Name "Clone01" -VM "Template01" -VMHost esxi01.example.com -Datastore datastore1

# Create VM from template
New-VM -Name "NewVM" -Template "Windows2019-Template" -VMHost esxi01.example.com -Datastore datastore1

# Modify VM CPU count
Set-VM -VM "WebServer01" -NumCpu 4 -Confirm:$false

# Modify VM memory
Set-VM -VM "WebServer01" -MemoryGB 8 -Confirm:$false

# Add hard disk to VM
New-HardDisk -VM "WebServer01" -CapacityGB 100 -StorageFormat Thin

# Add network adapter
New-NetworkAdapter -VM "WebServer01" -NetworkName "Production" -Type Vmxnet3 -StartConnected

# Create snapshot
New-Snapshot -VM "WebServer01" -Name "Pre-Update" -Description "Before applying updates"

# List snapshots
Get-Snapshot -VM "WebServer01"

# Revert to snapshot
Set-VM -VM "WebServer01" -Snapshot (Get-Snapshot -VM "WebServer01" -Name "Pre-Update") -Confirm:$false

# Remove snapshot
Remove-Snapshot -Snapshot (Get-Snapshot -VM "WebServer01" -Name "Pre-Update") -Confirm:$false

# Remove all snapshots
Get-Snapshot -VM "WebServer01" | Remove-Snapshot -Confirm:$false

ESXi Host Management

# List all hosts
Get-VMHost

# Get specific host
Get-VMHost -Name esxi01.example.com

# Get host information
Get-VMHost esxi01.example.com | Select Name, ConnectionState, PowerState, Version

# Enter maintenance mode
Set-VMHost -VMHost esxi01.example.com -State Maintenance -Confirm:$false

# Exit maintenance mode
Set-VMHost -VMHost esxi01.example.com -State Connected -Confirm:$false

# Reboot host
Restart-VMHost -VMHost esxi01.example.com -Confirm:$false

# Shutdown host
Stop-VMHost -VMHost esxi01.example.com -Confirm:$false

# Get host uptime
Get-VMHost | Select Name, @{N="Uptime";E={(Get-Date) - $_.ExtensionData.Summary.Runtime.BootTime}}

# Configure NTP servers
Add-VMHostNtpServer -VMHost esxi01.example.com -NtpServer "pool.ntp.org"

# Start NTP service
Get-VMHostService -VMHost esxi01.example.com | Where {$_.Key -eq "ntpd"} | Start-VMHostService

# Set NTP service to start automatically
Get-VMHostService -VMHost esxi01.example.com | Where {$_.Key -eq "ntpd"} | Set-VMHostService -Policy On

vMotion Operations

# Migrate VM to different host
Move-VM -VM "WebServer01" -Destination (Get-VMHost esxi02.example.com)

# Migrate VM to different datastore (Storage vMotion)
Move-VM -VM "WebServer01" -Datastore (Get-Datastore datastore2)

# Migrate VM to different host and datastore
Move-VM -VM "WebServer01" -Destination (Get-VMHost esxi02.example.com) -Datastore (Get-Datastore datastore2)

# Migrate multiple VMs
Get-VM Web* | Move-VM -Destination (Get-VMHost esxi02.example.com)

# Cross vCenter vMotion
Move-VM -VM "WebServer01" -Destination (Get-VMHost esxi03.remote.com -Server $remoteVC) -Datastore (Get-Datastore datastore3 -Server $remoteVC)

Cluster Management

# List all clusters
Get-Cluster

# Get specific cluster
Get-Cluster -Name "Production-Cluster"

# Create new cluster
New-Cluster -Name "New-Cluster" -Location (Get-Datacenter "DC1") -DrsEnabled -HAEnabled

# Enable DRS on cluster
Set-Cluster -Cluster "Production-Cluster" -DrsEnabled $true -DrsAutomationLevel FullyAutomated -Confirm:$false

# Enable HA on cluster
Set-Cluster -Cluster "Production-Cluster" -HAEnabled $true -HAAdmissionControlEnabled $true -Confirm:$false

# Add host to cluster
Add-VMHost -Name esxi01.example.com -Location (Get-Cluster "Production-Cluster") -User root -Password pass

# Get cluster resource pools
Get-Cluster "Production-Cluster" | Get-ResourcePool

# Get DRS recommendations
Get-Cluster "Production-Cluster" | Get-DrsRecommendation

# Apply DRS recommendations
Get-Cluster "Production-Cluster" | Get-DrsRecommendation | Apply-DrsRecommendation -Confirm:$false

Datastore Management

# List all datastores
Get-Datastore

# Get specific datastore
Get-Datastore -Name datastore1

# Get datastore capacity information
Get-Datastore | Select Name, @{N="CapacityGB";E={[math]::Round($_.CapacityGB,2)}}, @{N="FreeSpaceGB";E={[math]::Round($_.FreeSpaceGB,2)}}

# Find datastores with low free space
Get-Datastore | Where {$_.FreeSpacePercent -lt 20} | Select Name, FreeSpaceGB

# Mount NFS datastore
New-Datastore -Nfs -VMHost esxi01.example.com -Name "NFS-Datastore" -Path "/nfs/share" -NfsHost 192.168.1.100

# Remove datastore
Remove-Datastore -Datastore datastore1 -Confirm:$false

# Rescan datastores
Get-VMHost | Get-VMHostStorage -RescanAllHba -RescanVmfs

Networking Management

# List virtual switches
Get-VirtualSwitch

# Create standard switch
New-VirtualSwitch -VMHost esxi01.example.com -Name vSwitch1

# Add uplink to vSwitch
Get-VirtualSwitch -Name vSwitch1 | New-VirtualSwitchUplink -VirtualNetworkAdapter (Get-VMHostNetworkAdapter -Physical -Name vmnic1)

# Create port group
New-VirtualPortGroup -VirtualSwitch (Get-VirtualSwitch vSwitch0) -Name "Production" -VLanId 100

# List distributed switches
Get-VDSwitch

# Create distributed switch
New-VDSwitch -Name "DSwitch1" -Location (Get-Datacenter "DC1")

# Add host to distributed switch
Get-VMHost esxi01.example.com | Add-VDSwitchPhysicalNetworkAdapter -DistributedSwitch (Get-VDSwitch "DSwitch1") -VMHostPhysicalNic (Get-VMHostNetworkAdapter -Physical -Name vmnic2)

# Create distributed port group
Get-VDSwitch "DSwitch1" | New-VDPortgroup -Name "Production-DPG" -VlanId 100 -NumPorts 128

# Migrate VMs to distributed port group
Get-VM | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName "Production-DPG" -Confirm:$false

Template and Content Library

# Convert VM to template
Set-VM -VM "Windows2019-Master" -ToTemplate -Confirm:$false

# Convert template to VM
Set-Template -Template "Windows2019-Template" -ToVM -Confirm:$false

# Deploy VM from template
New-VM -Name "NewServer" -Template "Windows2019-Template" -VMHost esxi01.example.com -Datastore datastore1

# Get content libraries
Get-ContentLibrary

# Create content library
New-ContentLibrary -Name "Production-Library" -Datastore datastore1 -Description "Production templates"

# Get content library items
Get-ContentLibraryItem -ContentLibrary "Production-Library"

# Deploy VM from content library
New-VM -Name "NewVM" -ContentLibraryItem (Get-ContentLibraryItem -Name "Template01") -VMHost esxi01.example.com -Datastore datastore1

Reporting and Monitoring

# Generate VM inventory report
Get-VM | Select Name, PowerState, NumCpu, MemoryGB, @{N="UsedSpaceGB";E={[math]::Round($_.UsedSpaceGB,2)}} | Export-Csv "vm-inventory.csv"

# Get VM with most CPU usage
Get-VM | Sort-Object -Property CPUUsage -Descending | Select -First 10 Name, NumCpu, CPUUsage

# Get VM with most memory usage
Get-VM | Sort-Object -Property MemoryUsage -Descending | Select -First 10 Name, MemoryGB, MemoryUsage

# Get host resource utilization
Get-VMHost | Select Name, @{N="CPU Usage %";E={[math]::Round($_.CpuUsageMhz/$_.CpuTotalMhz*100,2)}}, @{N="Memory Usage %";E={[math]::Round($_.MemoryUsageGB/$_.MemoryTotalGB*100,2)}}

# Get VMs with snapshots older than 7 days
Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-7)} | Select VM, Name, Created, @{N="Age";E={(Get-Date) - $_.Created}}

# Find powered-off VMs
Get-VM | Where {$_.PowerState -eq "PoweredOff"} | Select Name, @{N="DaysPoweredOff";E={(Get-Date) - $_.ExtensionData.Runtime.PowerOffTime}}

# Get VMware Tools status
Get-VM | Select Name, @{N="Tools Status";E={$_.ExtensionData.Guest.ToolsStatus}}

# Check for VMs needing hardware upgrade
Get-VM | Where {$_.Version -lt "v13"} | Select Name, Version

Backup and Export

# Export VM to OVF
Export-VApp -Destination "C:\Exports" -VM "WebServer01" -Format OVF

# Import OVF/OVA
Import-VApp -Source "C:\Exports\template.ovf" -VMHost esxi01.example.com -Datastore datastore1

# Export vCenter configuration
Export-VIConfiguration -Destination "C:\Backup\vcenter-config.zip"

# Backup vCenter (VCSA)
# Use vCenter API or VAMI interface for VCSA backups

Advanced Operations

# Get VM guest info (requires VMware Tools)
Get-VM "WebServer01" | Get-VMGuest

# Run script in guest OS (requires VMware Tools)
Invoke-VMScript -VM "WebServer01" -ScriptText "Get-Service" -GuestUser Administrator -GuestPassword pass

# Copy file to VM
Copy-VMGuestFile -Source "C:\script.ps1" -Destination "C:\Temp\" -VM "WebServer01" -LocalToGuest -GuestUser Administrator -GuestPassword pass

# Copy file from VM
Copy-VMGuestFile -Source "C:\Logs\app.log" -Destination "C:\Temp\" -VM "WebServer01" -GuestToLocal -GuestUser Administrator -GuestPassword pass

# Get VM events
Get-VM "WebServer01" | Get-VIEvent -MaxSamples 100

# Get recent tasks
Get-Task -Status Error | Select Name, State, PercentComplete, StartTime

# Configure advanced VM settings
New-AdvancedSetting -Entity (Get-VM "WebServer01") -Name "isolation.tools.copy.disable" -Value $true -Confirm:$false

# Bulk VM operation
Get-VM Web* | ForEach-Object {
    Set-VM -VM $_ -MemoryGB 8 -Confirm:$false
    New-Snapshot -VM $_ -Name "Bulk Update" -Confirm:$false
}

Diagnostic Commands

# Generate support bundle
vm-support

# Generate support bundle with duration
vm-support -d 3600 -I

# Tail vmkernel log
tail -f /var/log/vmkernel.log

# View hostd log
tail -f /var/log/hostd.log

# Check VMware services status
/etc/init.d/hostd status
/etc/init.d/vpxa status

# Restart management agents
services.sh restart

# View system logs
vsi_traverse -l

# Check disk space
vdf -h

# Network troubleshooting
vmkping -I vmk0 192.168.1.1
esxcfg-nics -l
esxcfg-vmknic -l

# Check time sync
esxcli system time get

# View hardware health
esxcli hardware ipmi sel list

Best Practices

Command Line Best Practices

  • Always test commands in a non-production environment first
  • Use -WhatIf with PowerCLI to preview changes before execution
  • Script repetitive tasks for consistency and efficiency
  • Keep PowerCLI modules updated to latest version
  • Use proper authentication and secure credential storage
  • Document custom scripts and maintain version control
  • Enable SSH/ESXi Shell only when needed for security
  • Validate input parameters before executing bulk operations
  • Create backups before making significant configuration changes
  • Log command outputs for audit and troubleshooting purposes

Note: This command reference covers common operations. Always refer to official VMware documentation and PowerCLI cmdlet help for complete syntax and additional parameters. Use Get-Help cmdlet-name -Full in PowerCLI for detailed command information.