Top 4 – ESXi one-liner scripts

Datetime:2016-08-23 00:59:54          Topic: AWK           Share

I have caught myself quiet a few times running a bunch of one-liner scripts on ESXi.

Whether I setup ESXi, troubleshoot something or just test a feature, one-liners can often simplify whatever task you’re trying to complete.

Below is the list of one-liner scripts, which I use at least once a week.

Register all VMs, from a datastore, back to the ESXi Inventory

Add all VMs from datastore

Shell

find /vmfs/volumes/ -name "*.vmx" -exec  vim-cmd solo/registervm {} \;
find /vmfs/volumes/ -name "*.vmx" -exec  vim-cmd solo/registervm {} \;

Identify whether ESXi is booting of USB

Shell

esxcli storage core device list | grep 'Is Boot USB Device:' | awk '{ if($5=="true") {print "Found a usb boot device"}}'
esxclistoragecoredevicelist | grep 'Is Boot USB Device:' | awk '{ if($5=="true") {print "Found a usb boot device"}}'

Number of vmknics with jumbo frames configured

Number of vmknics with jumbo frames configured

Shell

esxcfg-vmknic -l | grep -Eo '[0-9]{1,}' | awk '{ if ((length($1) == 4 ) && $1 >= 9000 && $1 <= 9216) print}' | wc -l
esxcfg-vmknic -l | grep -Eo '[0-9]{1,}' | awk '{ if ((length($1) == 4 ) && $1 >= 9000 && $1 <= 9216) print}' | wc -l

Number of powered-on VMs

Number of powered-on VMs

Shell

esxcli vm proces list | grep "World ID:" | awk '{print $3}' | wc -l
esxclivmproceslist | grep "World ID:" | awk '{print $3}' | wc -l

I will share some of my most used PowerCLI scripts, early next 2016.





About List