VMware ESXi CLI Cheat Sheet

These cheat sheets are to be used on the VMware platform. Some commands require PowerCLI, others can be run directly on the Photon OS.

CommandWhat it does
/etc/init.d/hostd restart
/etc/init.d/vpxa restart
Restart VMWare Management services on Host
# Check if your VM has (Change Block Tracking) enabled or not
(Get-VM -Name Server_Name).ExtensionData.Config.ChangeTrackingEnabled
(Get-VM-Name Server_Name).ExtensionData.Config.ChangeTrackingEnabled
# Find VMs where CBT (Change Block Tracking) is Enabled
Get-VM| Where-Object{$_.ExtensionData.Config.ChangeTrackingEnabled-eq $true}
Check if Change Block Tracking enabled on VM
Get-VM | Get-NetworkAdapter | Select @{N=’VM’;E={$_.Parent.Name}},@{N=’AdapterName’;E={$_.Name}},@{N=’Type’;E={$_.Type}} | Where-Object{$_.Type -eq “e1000”}Get VM NIC with E1000
Get-vm | Select Name, @{N=”IP Address”;E={@($_.guest.IPAddress[0])}}Get VM IP
Get-VM | Select Name, @{N=”Cluster”;E={Get-Cluster -VM $_}}, @{N=”ESX Host”;E={Get-VMHost -VM $_}}, @{N=”Datastore”;E={Get-Datastore -VM $_}} |sort-object DatastoreGet VM Name, cluster, ESX , Datastore – and sort by Datastore
Get-VM | Get-NetworkAdapter | Select-Object Parent,TypeQuery the nic type of all virtual machines
get-vm | foreach-object -process {get-harddisk $_} | select-object storageformat | format-listQuery the disk type of all virtual machines
Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-90)} | Select-Object VM, Name, Created, SizeMBGet snapshots older than 3 months
Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-120)} | Remove-Snapshot -Confirm:$falseGet snapshots then remove them
Get-VM | Format-Table Name, @{Label=”NumSnapshots”;Expression={(Get-Snapshot -VM $_ | Measure-Object).Count}}Count number of snapshots
get-vm |% { get-view $_.id } | select Name, @{ Name=”;ToolsVersion”;; Expression={$_.config.tools.toolsVersion}}Get Vmware tools version
get-vmhost | select Name,@{Name=”Time”;Expression={(get-view $_.ExtensionData.configManager.DateTimeSystem).QueryDateTime()}}Get time off hosts
ForEach ($VM in Get-VM ){($VM.Extensiondata.Guest.Disk | Select @{N=”Name”;E={$VM.Name}},DiskPath, @{N=”Capacity(MB)”;E={[math]::Round($_.Capacity/ 1MB)}}, @{N=”Free Space(MB)”;E={[math]::Round($_.FreeSpace / 1MB)}}, @{N=”Free Space %”;E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})}Get Vms and free disk space
Get-VMHost | Sort Name | Get-View | Select Name, @{N=”CPU”;E={$_.Hardware.CpuPkg[0].Description}}Get Host CPU info
Get-Vmhost *Lists Vmhost 
 get-vmhost -datastore Datastore_NameGet Vmhosts on particular datastore
$esxihost | Get-VMHostServiceGet Vmhosts services
$esxihost | Get-VMHostService | where {$_.key -eq “TSM-SSH”}Find $vmhosts with SSH running
$esxihost | Get-VMHostService | where {$_.key -eq “TSM-SSH”} | Start-VMHostServiceStart SSH service on $exsihost
$esxihost | Get-VMHostService | where {$_.key -eq “TSM-SSH”} | Stop-VMHostServiceStop SSH service on $esxihost
Get-VM | Get-View | Select-Object Name, @{name=”toolsVersions”; Expression={$_.config.tools.toolsversion}}Get Vmware Tools versions
$esxihost | Get-VM | Get-SnapshotGet list of snapshots on $esxihost
$esxihost | Get-VM | Get-VMGuest | format-tableGet list of Guest Operating systems on $esxihost
get-vmhost | select Name,@{Name=”Time”;Expression={(get-view $_.ExtensionData.configManager.DateTimeSystem).QueryDateTime()}}Get time on all hosts
Get Detailed VM information
 Get-VMHost | Select @{N=”Cluster”;E={Get-Cluster -VMHost $_}}, Name, @{N=”NumVM”;E={($_ | Get-VM).Count}} | Sort Cluster, NameList how many VMs are running on a Host
ForEach ($VM in Get-VM ){($VM.Extensiondata.Guest.Disk | Select @{N=”Name”;E={$VM.Name}},DiskPath, @{N=”Capacity(MB)”;E={[math]::Round($_.Capacity/ 1MB)}}, @{N=”Free Space(MB)”;E={[math]::Round($_.FreeSpace / 1MB)}}, @{N=”Free Space %”;E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})}List all VM’s and their disk sizes
Get-VMHost | Sort Name | Get-View | Select Name, @{N=”CPU”;E={$_.Hardware.CpuPkg[0].Description}}Get Host CPU details
Get-VMHost |Sort Name |Get-View |Select Name, @{N=“Type“;E={$_.Hardware.SystemInfo.Vendor+ “ “ + $_.Hardware.SystemInfo.Model}},@{N=“CPU“;E={“PROC:“ + $_.Hardware.CpuInfo.NumCpuPackages + “ CORES:“ + $_.Hardware.CpuInfo.NumCpuCores + “ MHZ: “ + [math]::round($_.Hardware.CpuInfo.Hz / 1000000, 0)}},@{N=“MEM“;E={“” + [math]::round($_.Hardware.MemorySize / 1GB, 0) + “ GB“}} Get Host Hardware information
Get-VMHost | Get-VMHostNetwork | Select Hostname, VMKernelGateway -ExpandProperty VirtualNic | Where {$_.ManagementTrafficEnabled} | Select Hostname, PortGroupName, IP, SubnetMaskThis will then dump the ESXi Hostnames, IPs and Subnets – For the Management Network
Get-VMHost | Get-VMHostNetwork | Select Hostname, VMKernelGateway -ExpandProperty VirtualNic | Where {$_.vMotionEnabled} | Select Hostname, PortGroupName, IP, SubnetMaskThis will then dump the ESXi Hostnames, IPs and Subnets – For the vMotion Network
Get-VMHost | Get-Cluster | Select Name, DrsEnabled, DrsMode, DrsAutomationLevelDump DRS status
Get-VMHost | Get-Cluster | Select Name, VMSwapfilePolicyDump VMSwapfilePolilcy
Get-VMHost | Get-Cluster | Select Name, HAAdmissionControlEnabledCheck status of HA Admission Control
Get-VMHost | Get-Cluster | Select Name, HAFailoverLevel, HARestartPriority, HAIsolationResponseCheck HA Status Levels
Get-VMHost | Get-VMHostNetwork | Select Hostname, VMKernelGateway -ExpandProperty VirtualNic | Select Hostname, PortGroupName, IP, MTUCheck for MTU Mismatches
Get-VirtualSwitch | Select VMHost, Name, MTUShows what the MTU settings on the Virtual Switches are
Get-VMGuestNetworkInterface –VM VMNAME | Select VM, IP, SubnetMask, DefaultGateway, DnsDumps a hosts Name, IP, Subnet, Gateway and DNS configuration 
Get-VMHost | Get-ScsiLun | Select VMHost, ConsoleDeviceName, Vendor, MultipathPolicyThis will dump the Multipath Policy of the storage on the systems to determine what the MP configuration is. 
Get-VMHost | Sort Name | Select Name, @{N=”NTP”;E={Get-VMHostNtpServer $_}}This will dump NTP Configuration settings
Get-View -ViewType HostSystem | Sort Name | Select Name,@{N=”BIOS version”;E={$_.Hardware.BiosInfo.BiosVersion}}, @{N=”BIOS date”;E={$_.Hardware.BiosInfo.releaseDate}}This will dump the hosts BIOS version and date(s)
get-vmhost | Get-VMHostAdvancedConfiguration -Name Syslog.global.logHostDump the current SYSLOG Configuration
 $esxihost | Get-VM | Get-NetworkAdapter | Select @{N=’VM’;E={$_.Parent.Name}},@{N=’AdapterName’;E={$_.Name}},@{N=’Type’;E={$_.Type}} | Where-Object{$_.Type -eq “e1000”}Detailed E1000 details of $esxihost
Get-VIEvent -maxsamples 10000 |where {$_.Gettype().Name-eq “VmCreatedEvent” -or $_.Gettype().Name-eq “VmBeingClonedEvent” -or $_.Gettype().Name-eq “VmBeingDeployedEvent”} |Sort CreatedTime -Descending |Select CreatedTime, UserName,FullformattedMessage -First 10Find Vm’s Created last 10 days
$esxihost | Get-VM | Get-Snapshot | Select VM,Name,Created,sizegb,descriptionGet Snapshot details of $esxihost and list name, vmname, sizegb and snapshot description
$myvm | Get-NetworkAdapter | Select parent, name, type, networkname, connectionstate |Format-Table -AutoSizeDefine $myvms – lists network adapter details

You May Also Like

About the Author: VirtuallyThatGuy

2 Comments

  1. Thanks so much for sharing this.
    There are few commands that have invalid characters.
    Example:
    Get-VMHost | Sort Name | Select Name, @{N=”NTP”;E={Get-VMHostNtpServer $_}}

    It should probably look more like this:
    Get-VMHost | Sort Name | Select Name, @{N=’NTP’ ; E={Get-VMHostNtpServer $_}}

Leave a Reply

Your email address will not be published. Required fields are marked *