Coming Soon: GET:IT Endpoint Management 1-Day Conference on September 28th at 9:30 AM ET Coming Soon: GET:IT Endpoint Management 1-Day Conference on September 28th at 9:30 AM ET
VMware

ESX the PowerShell Way with Get-ESXCli

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.

Sponsored Content

Say Goodbye to Traditional PC Lifecycle Management

Traditional IT tools, including Microsoft SCCM, Ghost Solution Suite, and KACE, often require considerable custom configurations by T3 technicians (an expensive and often elusive IT resource) to enable management of a hybrid onsite + remote workforce. In many cases, even with the best resources, organizations are finding that these on-premise tools simply cannot support remote endpoints consistently and reliably due to infrastructure limitations.

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

ESX PowerShell Get-ESXCli 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.

ESX PowerShell Get-ESXCli

 

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

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.

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

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.

Related Topics:

Live Webinar: Active Directory Security: What Needs Immediate Priority!Live on Tuesday, October 12th at 1 PM ET

Attacks on Active Directory are at an all-time high. Companies that are not taking heed are being punished, both monetarily and with loss of production.

In this webinar, you will learn:

  • How to prioritize vulnerability management
  • What attackers are leveraging to breach organizations
  • Where Active Directory security needs immediate attention
  • Overall strategy to secure your environment and keep it secured

Sponsored by: