PowerShell is a terrific command line management tool. Of course, it can only peer into Windows-based systems, and naturally this doesn’t apply to a VMware server. However, PowerCLI offers a cmdlet that will bridge the gap between PowerShell and the VMware operating system. If you need to really get down deep into your VMware servers, Get-ESXCli is a tool that should fit the bill.
In this article, we’ll take a closer look at what Get-ESXCli can do, and some of the variables you can use with it to really examine the nitty-gritty detail of what is going on in your VMware environment.
Before we get started, make sure that you have PowerCLI loaded and you’re connected to an ESXi server. (Check out my series on PowerCLI, if you don’t already have it.)
The magic command is Get-ESXCli. To use, save the output to a variable.
PS C:> $esx = get-esxcli
What we end up with is like a proxy object to the ESX command line interface on the server. The object has a number of properties.
PS C:> $esx ================================ EsxCli: esx.jdhitsolutions.local Elements: --------- esxcli fcoe hardware iscsi network sched software storage system vm
These properties will include nested objects and methods that you can use to extract information from the server. For example, Figure 1 shows hardware elements.
You can navigate using an object.property notation.
PS C:> $esx.hardware.cpu ================== EsxCliElement: cpu Elements: --------- cpuid global Methods: -------- Cpu[] list()
The elements are properties. Or you might have a method to invoke. Don’t forget the parentheses. I have an example in Figure 2.
Once you know the “path” to the information you want, you can use a one-line command.
PS C:> $esx.system.hostname.get() DomainName FullyQualifiedDomainName HostName ---------- ------------------------ -------- jdhitsolutions.local esx.jdhitsolutions.local esx
You should be able to take the output and use other PowerShell cmdlets. Here’s an example to display volume usage.
PS C:> $esx.storage.filesystem.list() | Select VolumeName,Mounted,Size,Free,@{Name="PercentFree";Expression={"{0:P2}" -f ($_.Free/$_.size)}} | format-table
Finally, you can also ask for all of the commands that you can use with the ESXCli object. Think of it as like a Get-Command. Use the List() method from the esxcli.command namespace.
PS C:> $esx.esxcli.command.list() | format-list-group Namespace Command
To make it easier, I formatted the result as a list grouped by the namespace.
The namepace is in essence the path to use with your ESXcli variable. Once you know what you want, it is easy to get.
But be careful, especially with methods that will change something. These aren’t cmdlets, so there is no –WhatIf, and there’s no help documentation. This is definitely an area where you must learn in a non-production environment.
You should be able to handle most VMware management tasks with the existing cmdlet sets. The cmdlets are documented, designed to run in a pipeline, and for the most part self-describing. Even better, those cmdlets that will change the state of the VMware host or virtual machine support –Whatif and –Confirm, making them safe to use. But some IT pros will want or need to get down to the nitty-gritty of their VMware servers and a tool like Get-ESXCli is just what they need. If you use this cmdlet, I hope you’ll share why and how in the comments section.