2 minute read

Following the earlier post PowerCLI - Check MTU size configured in all hosts physical nics of a cluster lets see what more can we do with Get-EsxCli cmdlet.

Get-EsxCli is a cmdlet to run the esxcli command present in any ESXi shell, but from a Powershell shell.
   ReferenceGet-EsxCli

Having that in mind lets use examples to show how we can leverage it to get, or set, some host configuration in multiple hosts connected to a vCenter using Powershell scripting.

Lets check what is available to us: Get-EsxCli list Available commands

Lets now compare what is available in esxcli via command line: Get-EsxCli list Available commands

They are similar which will allow us to use the Get-EsxCli to get any information that we would be able to get via the esxcli in the ESXi shell.

Lets compare side by side the differences of using the two: Esxcli Get-EsxCli side by side

Note: as stated in the Get-EsxCli reference the use of -v2 is advised, since it is the only way of guarantee compatibility across different ESXi versions.
Being the info the same we should be able to use Get-EsxCli cmdlet to get/set the same information in multiple hosts.
There is a difference in the syntax as you can double check in the pictures above, but it is pretty straight forward to understand that the command tree is pretty much the same.

So now how can we use the Get-EsxCli cmdlet to configure something the same way we would do it with esxcli.

Lets use the example above and change the “Remote Host” value: Set Esxcli Get-EsxCli side by side

It becomes a bit more complicated however, it would be easier to create a simple oneliner Powershell script to get this change applied to an entire VMware cluster: Set Esxcli syslog cluster change

Summary of the commands used above:

Get-Cluster -Name "{cluster name}" | Get-VMHost | `
   %{ Write-Host $_.Name ; `
   (Get-Esxcli -v2 -VMHost $_).system.syslog.config.get.Invoke()}

Get-Cluster -Name "{cluster name}" | Get-VMHost | `
   %{ Write-Host $_.Name ; `
   (Get-Esxcli -v2 -VMHost $_).system.syslog.config.set.Invoke(@{loghost="{syslog IP/FQDN}"})}