Using the PSCredential Object with the Pure Storage PowerShell Toolkit

A great question came in yesterday about how to use the new –Credential parameter that was implemented in v2.5 Toolkit.

Question: What if someone wants to use the script the old way, and programmatically send the password?

Approach #1

Create a new credential variable and require a prompt for credentials entry via the traditional dialog box.

$Creds = Get-Credential

Now $Creds can be viewed with $Creds.Username and $Creds.Password. The Password is in the form of a System.Security.SecureString.

Then when creating a connection to the FlashArray you can pass the $Creds into the cmdlet.

$MySession = Get-PfaApiToken -FlashArray MyArray -Credential $Creds | Connect-PfaController

Approach #2

Create a new PSCredential object that can then be passed to the Get-PfaApiToken programmatically.

$Pwd = ConvertTo-SecureString "pureuser" -AsPlainText -Force
$Creds = New-Object System.Management.Automation.PSCredential ("pureuser", $pwd)
$MySession = Get-PfaApiToken -FlashArray MyArray -Credential $Creds | Connect-PfaController

Have a $Credentials day!


  1. Hi,

    I used a variant of the approach #2:
    I’m doing this in a ps window:

    I put the following result into $Pureuser_Key variable that i write into the script:
    ConvertTo-SecureString “$Password” -AsPlainText -Force | ConvertFrom-SecureString
    For instance:

    $Pureuser_Secure_Password = “$Pureuser_Key” | ConvertTo-SecureString
    $Pureuser_Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList “pureuser”,$Pureuser_Secure_Password
    $MySession = Get-PfaApiToken -FlashArray $MyArray -Credential $Pureuser_Credential | Connect-PfaController -HttpTimeOut 10000 -ErrorAction Stop

Add Comment

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

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