PowerShell and the Pure Storage FlashArray CLI

Scripting is a wonderful thing–saves me tons of time. PowerShell is no exception. VMware offers a very robust PowerShell cmdlet offering (called PowerCLI) which allows you to do essentially anything you can think of in vSphere. Of course this is all specific to VMware or Windows. What about including scripting commands for Pure Storage into PowerShell (PowerCLI) scripts? It is actually pretty simple using the readily available SSH plugin for PowerShell.


The Pure Storage CLI is not an installable CLI–it resides on the controllers of the FlashArray. So to execute commands you SSH into the virtual IP of the array and then do what you need to do. If you want to script Pure CLI commands you need to add the SSH module into PowerShell which enables SSH connections. Go to http://sshnet.codeplex.com/ and download the module. Then create a folder in your module folder (can be a few locations, run $env:PSModulePath to find the locations) called SSH-Sessions and make sure the SSH DLL is in there. (find more PowerCLI stuff for Pure here)

****UPDATE**** I highly recommend not using SSH in PowerShell anymore for Pure commands. Use the REST API–you will not regret it. Check it out here.

During your script (or interactive session) add the SSH module into the library with “Import-Module SSH-Sessions”. You will be able to invoke a SSH session now from PowerShell. Below is a sample script that translates a VMFS volume name (using PowerCLI and SSH) to its corresponding Pure Storage volume name:

#import SSH and PowerCLI modules
import-module SSH-Sessions
add-pssnapin VMware.Vimautomation.core
#set PowerShell policies
set-powercliconfiguration -invalidcertificateaction "ignore" -confirm:$false |out-null
set-executionpolicy remotesigned -force
#Retrieve information from user
$purevip = Read-host "Please enter the Pure FlashArray Virtual IP"
$pureuser = Read-host "Please enter the Pure FlashArray username"
$purepass = Read-host "Please enter the Pure FlashArray password" -AsSecureString
$vcuser = Read-host "Please enter the vCenter username"
$vcpass = Read-host "Please enter the vCenter password" -AsSecureString
$vcname = Read-host "Please enter the vCenter IP or FQDN"
$vmfs = Read-host "Please enter the datastore name"
#convert password back to plain text then create session with FlashArray
#convert password back to plain text then create session with FlashArray
$purepass = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
new-sshsession -computername $purevip -user $pureuser -password $purepass |out-null
$purepass = "0"
write-host "Connection to FlashArray successful" -foregroundcolor green
#convert password back to plain text then create session with vCenter
$vcpass = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
connect-viserver -server $vcname -user $vcuser -password $vcpass |out-null
$vcpass = "0"
write-host "Connection to vCenter successful" -foregroundcolor green
#get VMFS details
get-datastore $vmfs |get-scsilun |format-table -property CanonicalName |out-file EUI.txt
#extract extended unique identifier from result file
$eui = (get-content EUI.txt -totalcount 4)[-1]
rm EUI.txt
#get the last 16 digits from the EUI
$eui = $eui.substring(12)
#run CLI command through SSH
invoke-sshcommand -computer $purevip -quiet -command 'purevol list' |out-file volumes.txt
#select the string that matches the subset of the EUI to get the correct Pure volume info for the device
$purevol = get-content volumes.txt |select-string $eui.trimend()
$purevol =$purevol -split " "
$purevol =$purevol[0]
rm volumes.txt
#return the results to the screen
write-host "The Pure Volume name for the VMFS named " -nonewline; write-host $vmfs -nonewline; 
write-host " is" -nonewline
write-host $purevol -foregroundcolor green

Pretty straight forward–I didn’t add any error checking etc to keep the script simpler and easier to duplicate/understand. To understand some of the logic of how I made this translation take a look at the Network Authority Address (NAA). Here is a Pure volume NAA:


The NAA of this device is naa.624a9370753d69fe46db318d00011015. The 6 is not vendor specific but the 24a9370 is and it indicates Pure Storage:


Without getting too much deeper into the details the rest of the NAA identifies the volume itself. If you do a purevol list in the Pure CLI you will see the unique identifier of the volume(s):


You’ll notice the serial number of the device first listed matches the NAA of the device in vSphere starting at 753D69… I run a comparison of these two numbers to find the Pure volume name. Of course for the daily user it is easier to use the Pure Storage vSphere Web Client plugin to do this but for scripts this is useful. I was working with a customer last week to throw together a script to clone a VMFS and mount the new VMDKs to an existing VM for testing. So using the script above (and some more) the following script takes in some information and takes a Pure Storage array-based snap of a VMFS, mounts it, resignatures it and then add the VMDKs.

You can find the PowerShell script here in .doc format. vmcopy





2 thoughts on “PowerShell and the Pure Storage FlashArray CLI”

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.