ESXi CLIativity – Part 1

As I showed in a previous post, it is possible to do pretty awesome actions using the ESXi Shell.

By using VMware PowerCLI and some other tools, you can further extend these possibilities.
In this example we use a Windows workstation and the tool Plink.
Plink comes with the well known PuTTY utility and is a command-line connection tool similar to ssh and very useful for automated operations.

As an example, we use the unmap script from this post, the goal is to minimize manual actions. The first step is to deploy and start the unmap script on a more convenient way, without logon to the ESXi host.

The syntax for using plink is:

plink.exe <user>@<ESXi host> -pw <password> -m <command file>

The command file contains all actions you would normally manually perform. The command file for running the unmap script (named “unmap.plink”) can be found here.

A brief explanation of this command file.
The unmap script is created in the folder /tmp.
Lines 4 through 9, all starting with an echo statement handle the creation of the unmap script. Note the use of the escape character (backslash).
Line 4 creates the list with datastores to unmap.
Lines 10 through 12 make the script executable and start the unmap.

To run the script against a single host from the Windows workstation, do:

plink.exe root@esxi01 -pw secret -m ./unmap.plink

You can further extend the unmap script, e.g. selecting datastores by adding grep statements and conditional statements (if then else constructs).

In case you need to deploy the unmap script on multiple ESXi hosts, you can consider to also automate this step. For this we add some PowerShell.

The complete listing can be found here. Much of this PowerShell script is based on the script given in my previous post.

The most important part of this script is the function loop_through_all_hosts. In this function, SSH for an ESXi host will be enabled (line 120), Plink is executed on the next line (Line 121). This script assumes plink to be installed in: “C:\Program Files (x86)\PuTTY\ and the unmap.plink file to be available.

In the next part, I will show some more examples. As always, I thank you for reading.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: