VMware offers more command-line interfaces for vSphere than PowerCLI. One of them is the vSphere Command-Line Interface (CLI). The vSphere CLI has a command named esxcli
. PowerCLI has built-in support for this esxcli
command in the Get-EsxCli
cmdlet.
The syntax of the Get-EsxCli
cmdlet is as follows:
Get-EsxCli -VMHost <VMHost[]> [-V2] [[-Server] <VIServer[]>]
[<CommonParameters>]
Use the Get-EsxCli
cmdlet to connect to the esxcli
functionality of a host and save the connection in a variable $esxcli
:
PowerCLI C:> $esxcli = Get-EsxCli -VMHost 192.168.0.133
In the vSphere CLI, the command to get information about the CPUs in your host is:
C:>esxcli --server=192.168.0.133 hardware cpu list Enter username: root Enter password:
In PowerCLI, the command becomes a little different. The Get-EsxCLI
cmdlet returns a PowerShell object, and you have to use the properties and methods of this object to create the commands. This is why you have to put dots between all of the words in the command. And if the last word is a method, you have to specify parentheses for a parameter list even if there are no parameters. The command from the preceding example becomes the following in PowerCLI:
PowerCLI C:> $esxcli.hardware.cpu.list()
You can, of course, use the vSphere documentation to find the available esxcli
commands. But you can also use PowerCLI for help. If you type in a partial command, you will get a list of elements and methods that are possible for this command. Let's start with $esxcli
itself:
PowerCLI C:> $esxcli ===================== EsxCli: 192.168.0.133 Elements: --------- device elxnet esxcli fcoe graphics hardware iscsi network nvme rdma sched software storage system vm vsan
You can see that one of the elements is hardware
. Let's try hardware
as the next command:
PowerCLI C:> $esxcli.hardware ======================= EsxCliElement: hardware Elements: --------- bootdevice clock cpu ipmi memory pci platform smartcard trustedboot usb Methods: -------- string Help()
You now have all of the command elements you can use after hardware
. Let's try cpu
:
PowerCLI C:> $esxcli.hardware.cpu ================== EsxCliElement: cpu Elements: --------- cpuid global Methods: -------- Cpu[] list() string Help() string Help(string methodName)
And now you have obtained the list()
method that we used in the preceding example.
A lot of the esxcli
commands also provide a help()
method that gives information about the command. To get help about the $esxcli.hardware.cpu
command, type the following command:
PowerCLI C:> $esxcli.hardware.cpu.help() =================================================================== vim.EsxCLI.hardware.cpu ------------------------------------------------------------------- CPU information. ChildElement ------------------------------------------------------------------- - hardware.cpu.cpuid | Information from the CPUID instruction on ea | ch CPU. - hardware.cpu.globa | Information and configuration global to all l | CPUs. Method ------------------------------------------------------------------- - list | List all of the CPUs on this host.
If you want to know what the parameters for an esxcli
method are, you can use the vSphere documentation, or you can use the Get-Member
cmdlet:
PowerCLI C:> $esxcli.hardware.cpu | Get-Member TypeName: VMware.VimAutomation.ViCore.Impl.V1.EsxCli.EsxCliElementImpl Name MemberType Definition ---- ---------- ---------- Help CodeMethod string Help(); string Help(s... list CodeMethod vim.EsxCLI.hardware.cpu.list... cpuid CodeProperty VMware.VimAutomation.Sdk.Uti... global CodeProperty VMware.VimAutomation.Sdk.Uti... ConvertToVersion Method T VersionedObjectInterop.Con... Equals Method bool Equals(System.Object obj) GetHashCode Method int GetHashCode() GetType Method type GetType() IsConvertableTo Method bool VersionedObjectInterop.... ToString Method string ToString() ChildElements Property System.Collections.Generic.L... Client Property VMware.VimAutomation.ViCore.... FullName Property string FullName {get;} Id Property string Id {get;} IsManagedObjectInstance Property bool IsManagedObjectInstance... Methods Property System.Collections.Generic.L... Name Property string Name {get;} Uid Property string Uid {get;}
18.191.102.112