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 https://www.powershellgallery.com/api/v2/
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.
As always, I thank you for reading.