ESX the PowerShell Way with Get-ESXCli

Posted on November 18, 2013 by Jeff Hicks in VMware with 0 Comments

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.)

Get-ESXCli

The magic command is Get-ESXCli. To use, save the output to a variable.

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.

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.

ESX PowerShell Get-ESXCli hardware elements

Sponsored

You can navigate using an object.property notation.

The elements are properties. Or you might have a method to invoke. Don’t forget the parentheses. I have an example in Figure 2.

ESX PowerShell Get-ESXCli

 

Once you know the “path” to the information you want, you can use a one-line command.

 

Sponsored

You should be able to take the output and use other PowerShell cmdlets. Here’s an example to display volume usage.

ESX PowerShell Get-ESXCli volume

 

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.

To make it easier, I formatted the result as a list grouped by the namespace.

ESX PowerShell Get-ESXCli list of commands

 

The namepace is in essence the path to use with your ESXcli variable. Once you know what you want, it is easy to get.

ESX PowerShell Get-ESXCli namespace

 

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.

Sponsored

Tagged with , ,