ESXi CLIativity – Part 3

In previous post in this series, one and two, I showed you some examples how to run ESXi CLI commands on a more relaxed way with use of the PuTTY tools and some scripting.

In this post, I would like to introduce two other methods to execute ESXi CLI commands.


Microsoft Windows PowerShell and VMware PowerCLI are commonly used by VMware admins. The functionality of PowerShell can be extended by adding Modules. Since PowerShell version 5 adding Modules has become very easy with the introduction of repositories (external and internal). A repository is (said irreverently) a kind of app store where you can retrieve modules. The best known repository is the PowerShell Gallery. If this is all new, the link provides information to get your started, as well as many posts about this topic.

A very handy module is Posh-SSH, created by Carlos Perez, which extend PowerShell with SSH and SCP functionality. The following commands will check for the availability of the PowerShell Gallery and installs the Posh-SSH module.

PS C:\Users> Get-PSRepository

Name      InstallationPolicy   SourceLocation
----      ------------------   --------------
PSGallery Untrusted  

The Get-PSRepository should return the PSGallery as one of the repositories.

You can search for modules in the repository, e.g. the Posh-SSH module:

PS C:\Users> Find-Module -Name *ssh*

Version    Name     Repository    Description
-------    ----     ----------    -----------
2.0.2      Posh-SSH PSGallery     Provide SSH and SCP functionality for executing ...

The first line in the output of the Find-Module is the module we are looking for. To install the module:

PS C:\Users> Install-Module -Name Posh-SSH

Answer the “Untrusted repository” question with a “Yes” to continue the installation. How to use the new functionality?

This code sample, shows how to setup a session to an ESXi host, perform some action and close the session.

The best part…

For accessing an ESXi host over SSH, we still need to provide credentials. In environments with many hosts and unique passwords, this can become cumbersome when performing maintenance. But there is an alternative.

The esxcli command is the most important command for managing ESXi hosts. The esxcli command is not a single command but offers namespaces to manage aspects like system settings, storage, networking and so on. Besides running esxcli directly on an ESXi host, you can also run esxcli using the vSphere CLI or the vSphere PowerCLI (using the Get-EsxCli command). After setting up a connection to a vCenter Server, you can run any esxcli command against all ESXi hosts managed by the vCenter Server.

So, what if we could break-out esxcli and perform other commands, not (yet) supported by the esxcli?

Already in 2013, a smart guy, named Andreas Peetz, asked himself the same question and created a solution. As the esxcli command is extensible, he added a new namespace called “shell”, which exactly does what you would expect; running cli commands directly on the ESXi host.

For this to work, he created a VIB, which can be found here. In this post he explains how it all works.
For those interested how Andreas created this extension, please read this post.

As always, I thank you for reading.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: