ESXi – How to list OS discrepancies

As VMs get upgraded to newer OSes the VM Guest OS setup on the ESXi hosts migth no longer be the same as the OS version the VM is running (i.e. VM got upgraded from Win 7 to 10 but ESXi host still thinks it is running 7).

Here is a one liner that shows what is set and what is actually there:
Get-View -ViewType "VirtualMachine" -Property @("Name", "Config.GuestFullName", "Guest.GuestFullName") | Where-Object {($_.Config.GuestFullName -ne $_.Guest.GuestFullName) -and ($_.Guest.GuestFullName -ne $null)} | Select-Object -Property Name, @{N="Configured OS";E={$_.Config.GuestFullName}}, @{N="Running OS";E={$_.Guest.GuestFullName}} | Format-Table -AutoSize

The output look something like that:

Name                                  Configured OS                       Running OS
----                                  -------------                       ----------
win2K                                 Microsoft Windows 2000 Server       Microsoft Windows 2000 Professional
RH3                                   Red Hat Enterprise Linux 3 (32-bit) Red Hat Enterprise Linux 3 (64-bit)
suse51                                SUSE Linux Enterprise 11 (64-bit)   SUSE Linux Enterprise 12 (64-bit)

ESXi – How to configure and enable SNMP

Just a quick PowerShell script that sets up SNMP on ESXI hosts


#Script to enable and configure SNMP on ESXI host
Get-VMHost | Select Name
$host_name = Read-Host "Host name:"
$location="London HQ"
$esxcli = get-esxcli -vmhost $host_name
Write-host "Now go to the host and start the service"

Once that is done you still need to go the ESXi host and enable/start the SNMP service.

Managing VMware Tools advanced options in PowerShell

Here is a quick way of selecting the VMware Tools Advanced option: “Check and upgrade Tools during power cycling” for all VMs in a cluster. Here is a screen shot of the option in question:


And here is the script:

$vms = get-cluster "Cluster Name" | get-vm

foreach($vm in $vms) 
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.changeVersion = $vm.ExtensionData.Config.ChangeVersion
$ = New-Object VMware.Vim.ToolsConfigInfo
$ = "upgradeAtPowerCycle"
$_this = Get-View -Id $vm.Id

ESXI 6.0 monitoring SSD drive TBW

“Terabytes Written” is the total amount of data that can be written into an SSD before it is likely to fail.

There is a nicely written article on this blog explaining how to get the TBW for a SSD drive in ESXI host – open here.

However since I am a lazy kind of person I like to get stuff scripted and emailed to me.

In essence here is what I have done:

Install smartctl

  1. Download smartctl-6.6-4321.x86_64.vib
  2. Copy the VIB to the /tmp/ directory of an ESXi host
  3. SSH to the ESXi host
  4. Set the VIB acceptance level to CommunitySupported
    # esxcli software acceptance set --level=CommunitySupported
  5. Install the package (Maintenance Mode or Reboot is not required)
    #esxcli software vib install -v /tmp/smartctl-6.6-4321.x86_64.vib

The tool is located at /opt/smartmontools/smartctl and works just like the Linux version.
Locate physical disks with ls -l /dev/disks/

Create the script and automate
Save the below lines in a script somwehere:

 var=`/opt/smartmontools/smartctl -d sat --all /dev/disks/t10.ATA_____Samsung_SSD_850_EVO_M.2_250GB___________S24BNXAH119741P_____ | grep Total_LBAs | cut -d"-" -f2`
 TBW=`awk "BEGIN {print $var*512/1099511627776}"`
 echo "Total TB Writen so far: " $TBW

var2=`/opt/smartmontools/smartctl -d sat --all /dev/disks/t10.ATA_____Samsung_SSD_850_EVO_M.2_250GB___________S24BNXAH119741P_____ | grep Power_On | cut -d"-" -f2`
 POWERON=`awk "BEGIN {print $var2/24}"`
 echo "Device in use since [days]: " $POWERON

echo "Device has 5 Years Limited Warranty or 75TBW Limited "
 REMAIN=`awk "BEGIN {print (75*$POWERON)/$TBW}"`
 echo "Device has approximately: " $REMAIN "days left"
 REMAINY=`awk "BEGIN {print $REMAIN/360}"`
 echo "that is approx. $REMAINY years left"


To see how much life my SSD drive has got left I added that script to /etc/profile.local file so whenever I login I get something like that:

Samsung SSD 850 Evo m.2 250GB Remaining Disk LifeTime
Tue May 24 16:30:12 UTC 2016

Total TB Written so far: 1.26013
Device in use since [days]: 97.9167
Device has 5 Years Limited Warranty or 75TBW Limited
Device has approximately: 5827.77 days left
that is approx. 16.1883 years left

As I don’t often login to my esxi host via ssh I created a cron job – /var/spool/cron/crontabs/root :

0    0   1,15 *  *    source /opt/smartmontools/ > /opt/smartmontools/disklifetime.txt

and specified it to run every two weeks and save the results to a file. That file is then picked up (via scp) by my linux server and emailed to me.

Job done.

Intel NUC – Install USB Ethernet Adapter

The only letdown with Intel NUC is the only one Ethernet adapter. Luckily thanks to some great minds out there there is a way out of this.
All is needed is a Startech USB 3.0 to Gigabit Ethernet Adapter (Part Number: USB31000S) and the USB driver for ESXI downloadable from here:

UPDATE (1/1/18) – Updated driver for ESXi 6.5, details here.

    • Download the driver – ESXI 6u2 driver – see above github link
    • Transfer the vib file to your ESXI host
scp vghetto-ax88179-esxi60u2.vib root@esxi:/
    • Ensure that your NUC has USB 3 adapter enabled
[root@esxi:~] lsusb
 Bus 002 Device 002: ID 0b95:1790 ASIX Electronics Corp. AX88179 Gigabit Ethernet
 Bus 001 Device 005: ID 8087:0a2b Intel Corp.
 Bus 001 Device 003: ID 0951:1665 Kingston Technology Digital DataTraveler SE9 64GB
 Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    • Install the vib driver:
[root@esxi:~] esxcli software vib install -v /vghetto-ax88179-esxi60u2.vib -f
 Installation Result
 Message: Operation finished successfully.
 Reboot Required: false
 VIBs Installed: virtuallyGhetto_bootbank_vghetto-ax88179-esxi60u2_6.0.0-1.0.0
 VIBs Removed:
 VIBs Skipped:
    • Verify that it was installed correctly:
[root@esxi:~] esxcli network nic list
 Name PCI Device Driver Admin Status Link Status Speed Duplex MAC Address MTU Description
 ------ ------------ ------------ ------------ ----------- ----- ------ ----------------- ---- --------------------------------------------
 vmnic0 0000:00:1f.6 e1000e Up Up 1000 Full b8:ae:ed:7d:e2:d5 1500 Intel Corporation Ethernet Connection I219-V
 vusb0 Pseudo ax88179_178a Up Up 1000 Full 00:24:9b:16:33:f8 1500 Unknown Unknown