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!

barkz

2 comments
  1. Hi,

    I used a variant of the approach #2:
    I’m doing this in a ps window:
    $Password=”pureuser”

    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_Key=”01000000d08c9ddf0115d1118c7a00c04fc297eb010000001df078edba0b8644a18c9c7a0921f1e00000000002000000000003660000c000000010000000664e1f7379031a569622b57d4b044f200000000004800000a0000000100000007528676d35e19049608e5bf2026d2f3d1800000038ef3efcefe8ac0119b4bc1070f41cb1bd680ba14e557a9f140000008a916156eb775211d68e4c9ba32aa07d64bcf9ad”

    Then:
    $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

Leave a Reply to PureSam Cancel Reply

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.