Quick Tip : How to Format the output of ESXCLI command?

Favorite command Next to ESXTOP for many VMware administrators will be ESXCLI. It provides you with the handfull of information, which you are really looking for.You can manage many aspects of an ESXi host with the ESXCLI command set.You can run ESXCLI commands as vCLI commands or run them in the ESXi Shell in troubleshooting situations.You can also run ESXCLI commands from the PowerCLI shell by using the Get-EsxCli cmdlet. Below are the Available namespaces which are available as part of ESXCLI command.

ESXCLI-Formatting-output-1With ESXCLI, the output of the command is formatted using a “default” formatter based on the type of data being displayed. However, you can easily modify the output by using one of the three supported formatters: xml, csv and keyvalue by using the command “ESXCLI –Formatter” option.

Formatting the Output of ESXCLI:

Let’s focus on how to use the ESXCLI command to get the output formatted. In may use cases, We may want to import the output data to Excel Spreedsheet to send the report to your manager or even it can be used during maintenance.  Default output of esxcli command will not really allow you to properly copy the formatted data  for excel because of default formatter. Even you may also not interested with the all the fields of your ESXCLI output. You may be interested with some specific fields in the ouput.

Let’s consider the output of the command: esxcli network nic list

ESXCLI-Formatting-output-2You  may not really interested in the all the fields of the output. You really want the output with only 4 fields (Name,Driver,Speed & MTU). Let me use esxicli formatter option.

esxcli –formatter=csv –fromat-param-fields=”Name,Driver,Speed,MTU” network nic list

ESXCLI-Formatting-output-3Example 2:

I have total of 24 CPU’sThe below command gives me output for around 5 pages but i am only interested with ID, Brand,Corespeed  & ClockSpeed.

esxcli hardware cpu list

ESXCLI-Formatting-output-4Let use the esxcli –formatter option to pull only the interested fields (ID,Brandd,Core Speed & Bus Speed)

esxcli –formatter=csv –format-param=fields=”ID,Brand,Core Speed,Bus Speed” hardware cpu list

ESXCLI-Formatting-output-5You can simply use the Text import wizard in Excel and import the data and separate the fields with Comma.

ESXCLI-Text Import Wizard

Data is simply exported into Excel spreadsheet.

ESXCLI- Export to excelThat’ it. We are done with the formatting of the ESXCLI command output. Similarly you can use the formatter option to format the output of  various ESXCLI commands. I hope this is informative for you. Thanks for Reading !!! Be Social and share it in social media, if you feel worth sharing it.