Default FlashArray Connection With PowerShell

In the VMware Pure PowerShell module (PureStorage.FlashArray.VMware) there is a default array connection stored in a global variable called $Global:DefaultFlashArray and all connected FlashArrays in $Global:AllFlashArrays. The VMware/Pure PowerShell module automatically uses what is in the “default” variable.

The underlying “core” Pure Storage PowerShell module (PureStoragePowerShellSDK) does not yet take advantage of global connections. So for each cmdlet you run, you must pass in the “array” parameter. For example to get all of the volumes from an array:

Kind of annoying if you are interactively running commands and only have one array connection you care about (or one that you primarily care about).

But there is a nice option in PowerShell to help you with this! Default parameter values. In every cmdlet the input for the array connection is -array.

So let’s say I use new-pfaarray to create a new FlashArray connection and store the connection in the variable $flasharray.

$flasharray = new-pfaarray -endpoint 10.21.202.60 -credentials (get-credential) -ignoreCertificateError 

I can then run this:

$PSDefaultParameterValues = @{

    "*-pfa*:Array"=$flashArray;
}

This will then default any parameter named “array” to the value in $flasharray of the parameter was not specifically entered. Furthermore, it will be only for cmdlets with -pfa in their name, which generally should therefore only be for cmdlets in the PureStoragePowerShellSDK. I looked at ways of including the fully-qualified module name in the default parameter rule (only default the “-array” parameter if the cmdlet is in this module) and there doesn’t seem to be a clean way to do that other than explicitly grabbing each cmdlet and making a rule for it.

This is also fairly straight-forward. Once again, connect to a FlashArray:

flasharray = new-pfaarray -endpoint 10.21.202.60 -credentials (get-credential) -ignoreCertificateError 

Then run:

$psCMDs = (get-command -Module PureStoragePowerShellSDK).Name
$defaultParamHash = @{}
foreach ($psCMD in $psCMDs)
{
    $defaultParamHash.Add("$($psCMD):Array",$flashArray)
}
$PSDefaultParameterValues = $defaultParamHash

The above pulls all of the cmdlets from the PureStoragePowerShellSDK module and make a specific rule for each (if “array” is not specified, default to this value (specified array connection).

Either of the above options will result in you no longer having to explicitly pass in a FlashArray connection each time you run a base PureStoragePowerShellSDK command:

6 Replies to “Default FlashArray Connection With PowerShell”

  1. Hi Cody,
    I wanted to get a list of all the flash arrays that are connected to my vcenter. Is there a way to do it from PowerCLI ?

    According to my use case, I need to know the IP of a flash array connected to a particular DataStore.

    1. If you use the module here: https://www.powershellgallery.com/packages/PureStorage.FlashArray.VMware/

      This is possible with the cmdlet get-pfaconnectionofdatastore. Just connect to your FlashArrays and then pass in a datastore to the cmdlet and it will tell you which FA hosts it. The FA object which is returned has a property called .endpoint which will be the FQDN or IP of the FlashArray.

      See:

      PS C:\Users\cody> get-help Get-PfaConnectionOfDatastore -Detailed

      NAME
      Get-PfaConnectionOfDatastore

      SYNOPSIS
      Takes in a vVol or VMFS datastore, one or more FlashArray connections and returns the correct connection.

      SYNTAX
      Get-PfaConnectionOfDatastore [[-flasharrays] ] [-datastore] []

      DESCRIPTION
      Will iterate through any connections stored in $Global:AllFlashArrays or whatever is passed in directly.

      PARAMETERS
      -flasharrays

      -datastore


      This cmdlet supports the common parameters: Verbose, Debug,
      ErrorAction, ErrorVariable, WarningAction, WarningVariable,
      OutBuffer, PipelineVariable, and OutVariable. For more information, see
      about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).

      ————————– EXAMPLE 1 ————————–

      PS C:\>PS C:\ $faCreds = get-credential

      PS C:\ New-PfaConnection -endpoint flasharray-m20-2 -credentials $faCreds -defaultArray
      PS C:\ New-PfaConnection -endpoint flasharray-x70-1 -credentials $faCreds -nondefaultArray
      PS C:\ New-PfaConnection -endpoint flasharray-x70-2 -credentials $faCreds -nondefaultArray
      PS C:\ $ds = get-datastore MyDatastore
      PS C:\ Get-PfaConnectionOfDatastore -datastore $ds

      1. For making connections to the flash arrays, I should know the endpoints of them. Let’s assume that I am unaware of the flash arrays that are connected but I want to establish a connection to all of them. Is there a way to find out all the flash arrays in my vCenter ?

        1. So let’s work backwards. You can identify the serial number of the volume that hosts the datastore and in that serial you can figure out the array serial number. But eventually you need to connect to a FA to confirm it is on that FlashArray. So let me ask you a bit more specifically, what is your end goal? Once you identify the FlashArray, what do you need to do? Because actually using the Pure1 API is a better choice if you just want to know which array.

          1. After identifying the FlashArray I wanted to find out the volume that hosts the datastore. And further using that information I can expand my volume if requirement comes up. As of now I am creating a connection with all the Flash Arrays manually and then checking for the connection with the datastore as mentioned by you. It helped. Thanks 🙂

            Well, I needed help on more issue regarding PowerCLI, my java program is unable to identify the PowerCLI Modules.
            For ex-
            Connect-VIServer -Server VCenter-IP
            connects from Powershell but when I try to execute it from a script (which is getting called from a Java Program) it throws error that it is not able to identify Connect-VIServer.

  2. After identifying the FlashArray I wanted to find out the volume that hosts the datastore. And further using that information I can expand my volume if requirement comes up. As of now I am creating a connection with all the Flash Arrays manually and then checking for the connection with the datastore as mentioned by you. It helped. Thanks 🙂

    Well, I needed help on more issue regarding PowerCLI, my java program is unable to identify the PowerCLI Modules.
    For ex-
    Connect-VIServer -Server VCenter-IP
    connects from Powershell but when I try to execute it from a script (which is getting called from a Java Program) it throws error that it is not able to identify Connect-VIServer.

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.