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:

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.