These cheat sheets are to be used on the VMware platform. Some commands require PowerCLI, others can be run directly on the Photon OS.
Command | What 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 Datastore | Get VM Name, cluster, ESX , Datastore – and sort by Datastore |
Get-VM | Get-NetworkAdapter | Select-Object Parent,Type | Query the nic type of all virtual machines |
get-vm | foreach-object -process {get-harddisk $_} | select-object storageformat | format-list | Query the disk type of all virtual machines |
Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-90)} | Select-Object VM, Name, Created, SizeMB | Get snapshots older than 3 months |
Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-120)} | Remove-Snapshot -Confirm:$false | Get 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_Name | Get Vmhosts on particular datastore |
$esxihost | Get-VMHostService | Get Vmhosts services |
$esxihost | Get-VMHostService | where {$_.key -eq “TSM-SSH”} | Find $vmhosts with SSH running |
$esxihost | Get-VMHostService | where {$_.key -eq “TSM-SSH”} | Start-VMHostService | Start SSH service on $exsihost |
$esxihost | Get-VMHostService | where {$_.key -eq “TSM-SSH”} | Stop-VMHostService | Stop 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-Snapshot | Get list of snapshots on $esxihost |
$esxihost | Get-VM | Get-VMGuest | format-table | Get 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, Name | List 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, SubnetMask | This 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, SubnetMask | This will then dump the ESXi Hostnames, IPs and Subnets – For the vMotion Network |
Get-VMHost | Get-Cluster | Select Name, DrsEnabled, DrsMode, DrsAutomationLevel | Dump DRS status |
Get-VMHost | Get-Cluster | Select Name, VMSwapfilePolicy | Dump VMSwapfilePolilcy |
Get-VMHost | Get-Cluster | Select Name, HAAdmissionControlEnabled | Check status of HA Admission Control |
Get-VMHost | Get-Cluster | Select Name, HAFailoverLevel, HARestartPriority, HAIsolationResponse | Check HA Status Levels |
Get-VMHost | Get-VMHostNetwork | Select Hostname, VMKernelGateway -ExpandProperty VirtualNic | Select Hostname, PortGroupName, IP, MTU | Check for MTU Mismatches |
Get-VirtualSwitch | Select VMHost, Name, MTU | Shows what the MTU settings on the Virtual Switches are |
Get-VMGuestNetworkInterface –VM VMNAME | Select VM, IP, SubnetMask, DefaultGateway, Dns | Dumps a hosts Name, IP, Subnet, Gateway and DNS configuration |
Get-VMHost | Get-ScsiLun | Select VMHost, ConsoleDeviceName, Vendor, MultipathPolicy | This 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.logHost | Dump 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 10 | Find Vm’s Created last 10 days |
$esxihost | Get-VM | Get-Snapshot | Select VM,Name,Created,sizegb,description | Get Snapshot details of $esxihost and list name, vmname, sizegb and snapshot description |
$myvm | Get-NetworkAdapter | Select parent, name, type, networkname, connectionstate |Format-Table -AutoSize | Define $myvms – lists network adapter details |
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 $_}}
yeah this fixed now