Today I am going to talk about an interesting feature of PowerCLI. Through PowerCLI you can utilize the full functionalities of ESXCLI commands. Question is why would you like to access Esxcli commands from PowerCLI cmdlets. The reason is there are certain tasks which can easily be done using Esxcli cmdlets because there are no simple cmdlets available in PowerCLI for this.
For example, if you want to re-signature a vmfs datastore, it is easier to use Esxcli than to use PowerCLI and vSphere API’s. Besides using Esxcli very easily provides access to low level information about esxi server.
To access the Esxcli commands, first we need to connect to an Esxi server directly and then use the Get-EsxCli cmdlet to access the ESXCli commands. I will first connect to a Esxi server.
PS C:> Connect-VIServer esxi1.lab.com -Username root -Password abcxyz
Next we will store the information in a variable $esxinfo.
PS C:> $esxinfo = Get-EsxCli -VMHost Esxi1.lab.com
So we have stored ESX CLI cmdlets in the variable. Now if we check the variable we can get a list of all the cmdlets.
PS C:> $esxinfo ===================== EsxCli: esxi1.lab.com Elements: --------- device elxnet esxcli fcoe graphics hardware iscsi network rdma sched software storage system vm vsan
Ok. So good so far. Since we got the list, what to do with it? To dig deeper, we need to query further. For example, if we need to find the information about hardware, we need to query it.
PS C:> $esxinfo.hardware ======================= EsxCliElement: hardware Elements: --------- bootdevice clock cpu ipmi memory pci platform smartcard trustedboot
As can be seen from above that we can get information about the listed parameters. For example, if we want to know about the platform we can simply use it with do notation.
PS C:> $esxinfo.hardware.platform ======================= EsxCliElement: platform Methods: -------- PlatformGet get()
We can see that there is only one method get() defined in this parameter. So we can use this to get the information about the platform.
PS C:> $esxinfo.hardware.platform.get() IPMISupported : false ProductName : VMware Virtual Platform SerialNumber : VMware-56 4d a2 7e 02 05 10 2b-77 8b 50 eb bc b8 0b 78 UUID : 0x56 0x4d 0xa2 0x7e 0x2 0x5 0x10 0x2b 0x77 0x8b 0x50 0xeb 0xbc 0xb8 0xb 0x78 VendorName : VMware, Inc.
Likewise you can use different parameters to get or set many aspects of Esxi servers which you can do from ESX CLI cmdlets, but this time from PowerCLI.