Using PowerCLI to correlate VMware VMFS and ScaleIO volume info

In my previous post I wrote about expanding a ScaleIO volume in a VMware environment. During that procedure there is a requirement  to correlate the EUI of the device hosting the VMFS to the ScaleIO identifier so that you can ensure that you actually expand the correct volume. Especially important in large environments. So I thought is there a way to script this correlation in a simple fashion to save you some work? Can the whole process be automated?

The answer to both is yes!


There are probably a million ways to script this and a million different scripting languages that could be used, but I went for a combination of three; PowerCLI for its ease of use with VMware (and most VMware people are probably at least sort of familiar with it) and of course SCLI for the ScaleIO work. The third would be PowerShell of course.

So what do we need to get this working? A few things…

  1. A Windows host
  2. PowerCLI. I used the latest version, 5.5.
  3. ScaleIO installed and configured, this is version 1.20
  4. To enable SSH via Powershell you need to download an add-in from
  5. Powershell 3.0 installed
  6. Microsoft 4.0+ (I used 4.5) .net Framework

There are a couple of steps to configure the SSH add-in but there is not reason for me to reinvent the wheel, these steps are well-documented here: This is also helpful later on for using the new cmdlets it provides:

The tricky part (only in the sense that it is not specifically well-documented) is authorizing the connection for SSH. There are a few ways to do this (username/password doesn’t work by default in an automated script) so I opted for simply creating a private/public key that the Powershell session can reference for authentication to the ScaleIO Metadata Manager (MDM).

Once again a few ways to do this, such as puttygen or the built-in Linux keygen. The ScaleIO VMs have the ssh-keygen command built in so that is what I opted for. So to generate the keys, just SSH into the MDM and run the following:


This will take you through a quick command line wizard to create the keys. It asks you to name the keys and what location, put them in /root/.ssh/. Therefore the public key automatically is where it is supposed to end up. Name it something that makes sense. I will choose the name “scio” to signify the key is for ScaleIO. I left the passphrase empty.

keygenPretty straight forward. So the keys are now in the /root.ssh/ directory. The public key needs to be added to the authorized keys store on the MDM and most likely that doesn’t even exist yet. If it doesn’t, the simplest thing to do is to just rename “” to “authorized_keys”. No file extension. It must stay in the /root/.ssh/ directory.

The private key is the one without an extension. Use SCP to move the file from the MDM to the Windows host you intend on running the script from.

Now you are ready to use PowerShell.

In PowerShell, there are a few “prep” commands you need to run to be able to use SSH and PowerCLI commands:

To import the SSH module:

import-module SSH-Sessions

To import PowerCLI:

add-pssnapin VMware.Vimautomation.core

And some management commands:

set-executionpolicy remotesigned -force

set-powercliconfiguration -invalidcertificateaction "ignore" -confirm:$false

Now off to the races. Let’s initiate our SSH session and our connection to the vCenter. The new-sshsession cmdlet creates the SSH session and connect-viserver connects to the vCenter as see below:

new-sshsession -computername <IP of MDM> -user root -keyfile <Windows location of private key>

connect-viserver -server <vCenter> -user <username> -password <password>

The image below shows the whole PowerShell process up until now.


So now we are connected to both the vCenter server and the primary ScaleIO MDM. If you use the ScaleIO virtual IP instead of a direct MDM IP you will want to make sure both the primary MDM and the secondary MDM have the correct public key to accept the connection.

The first thing we want to do is to get the information of a given VMFS volume, the important part is the Extended Unique Identifier (EUI). Using the PowerCLI cmdlet “get-datastore” and the name of the datastore, we can get what we need. So in my case the VMFS is named “ScaleIO_ds2”.

get-datastore ScaleIO_ds2 |get-scsilun |format-table -property CanonicalName

This will return the canonical name of the device which is the EUI. Note that it will return it once per host that can see the volume. In my case, four hosts can see the VMFS so the EUI is returned four times:



If you remember from my previous post, the last 16 digits of the EUI is the ScaleIO volume identifier, so we need to use some PowerShell trickery to store that portion in order to match it with a volume with SCLI. You can see how I did this in my script in the end of this post (some sorting, truncating etc.).

So now we have the identifier of e766c8ea00000001 saved in a PowerShell object. It is time to execute SCLI commands via the SSH session that is active. The cmdlet, “invoke-sshcommand” will do the trick. The simplest SCLI command to retrieve volume identifiers is the “scli –query_all_volumes” operation. So it would look similar to this:

invoke-sshcommand -computer <MDM IP> -command 'scli --query_all_volumes'

invokesshcommandThis command will return the results to the screen twice, one that is essentially printed to the screen and the other which can be captured by PowerShell, so in my script I store the results in a text file temporarily. After parsing the text file and using the storage last portion of the provided EUI I can match a ScaleIO identifier in the text file (and its respective information) to it. This leaves me with the following returned:

Volume ID e766c8ea00000001 Name: scio-vol2 Storage pool: scio-pool1 Size:1 TB (1024 GB)

So for the given EUI this is the volume name, size and storage pool for that VMFS volume. The basic PowerShell operations I used are below:

import-module SSH-Sessions
add-pssnapin VMware.Vimautomation.core
set-powercliconfiguration -invalidcertificateaction "ignore" -confirm:$false
set-executionpolicy remotesigned -force
new-sshsession -computername -user root -keyfile c:usershostecdesktopid_rsa
connect-viserver -server ch-scio-vc1 -user root -password vmware
get-datastore ScaleIO_ds2 |get-scsilun |format-table -property CanonicalName |out-file EUI.txt
$eui = (get-content EUI.txt -totalcount 4)[-1]
rm EUI.txt
$eui = $eui.substring(20)
invoke-sshcommand -computer -command 'scli --query_all_volumes' |out-file volumes.txt
$scio = get-content volumes.txt |select-string $eui.trimend()
$scio = $scio -replace ">> ", ""
rm volumes.txt

Pretty simple. With this we could make a smarter script that interactively takes information in as input from a user and then returns the ScaleIO information to the screen, allowing for more flexibility. See a GIF demo of that script below. The PowerShell script itself is attached below that in a Word document.


There better ways to do this? Probably! Let me know in the comments.

In the end the combination of these can allow you do some cool stuff. ScaleIO back to VMware information, automatically expand volumes and resize the VMFS etc.

Download the script here (.doc):




One thought on “Using PowerCLI to correlate VMware VMFS and ScaleIO volume info”

Leave a Reply

Your email address will not be published. Required fields are marked *

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