Using the Pure1 PowerShell Module

Recently I wrote a blog post on how to authenticate and connect to Pure1 via PowerShell. You can find that here:

I have made authentication MUCH easier:

https://www.codyhosterman.com/2019/12/pure1-rest-api-authentication-made-easy/

But it is fairly involved, so I made it easier for you (and me) by writing a PowerShell module and posted in on the PowerShell Gallery.

https://www.powershellgallery.com/packages/Cody.PureStorage.Pure1/

This is fairly limited right now, so keep an eye on it as a I update it. Currently it has three cmdlets:

  • Get-PureOneArrays
  • New-PureOneRestConnection
  • New-PureOneRestOperation

As I add updates you can see them here:

https://www.codyhosterman.com/scripts-and-tools/pure1-rest-api/pure1-powershell-module/

The command new-pureonerestconnection connects to Pure1 for you. All you need to do is pass it your application ID and your certificate.

I am pulling my certificate from the Windows certificate store:

$CertObj = Get-ChildItem Cert:\LocalMachine\my\9A3F43947557B299FD9821B56719C635A6338A0F

Storing it in $certobj. You find more information on certificates here:

Then install/load the module with:

install-module Cody.PureStorage.Pure1
import-module Cody.PureStorage.Pure1

When I release new versions, just run:

update-module Cody.PureStorage.Pure1

Now pass your application ID and certificate into the connection cmdlet.

New-PureOneRestConnection -certificate $CertObj -pureAppID "pure1:apikey:VIx9l8Do5W9tiYrL"

It does not return any value. Instead it stores the access token in a global variable: $Global:pureOneRestHeader. This makes things easier–you do not need to pass the authentication into subsequent commands. Very similar to have vCenter connections work in PowerCLI.

The second currently cmdlet is for retrieving arrays, Get-PureOneArrays.

If you run it with no parameters, it will return all of your arrays.

Get-PureOneArrays

You can also add in an array ID, an array name, or array product (FlashArray or FlashBlade).

Get-PureOneArrays -arrayName "sn1-m50-b01-33"
Get-PureOneArrays -arrayId "sn1-m50-b01-33"

Or just ask for all of your FlashBlades:

Get-PureOneArrays -arrayProduct FlashBlade

Now there is a lot more information you can pull from Pure1 besides what you see above–I will work on adding more cmdlets. Array busy meter, performance, tags, volumes, file systems, snapshots, etc.

Until then, I create another cmdlet that allows you to run any REST operation called new-pureOneRestOperation. Uses the same authentication as above, but allows you to enter in a custom resource type (arrays, volumes, etc), a JSON body, and or custom queries or filters.

In the below case, I am adding a key/value tag to my array called sn1-420-a09-14. For how to format and what options you have, just look at our REST documentation.

https://support.purestorage.com/Pure1/Pure1_Manage/Pure1_Manage_-REST_API/Pure1_Manage-_REST_API__Reference

New-PureOneRestOperation -restOperationType PUT -resourceType "arrays/tags/batch" -queryFilter "
?resource_names='sn1-420-a09-14'" -jsonBody '[{"key":"test-tag","value":"testcody-ps"}]'

Enjoy!!

10 Replies to “Using the Pure1 PowerShell Module”

  1. I kept getting a 400 error on methods that involved using a filter for array names or IDs. Might need to update your module to URL encode the square brackets (“[” and “]”). After updating your module to use the encoded values (“%5B” and “%5D”), I no longer got any errors.

    1. Could you post an example of what you were running that returned that error? I am able to pass in array names in the cmdlets right now. I want to fix this I am just not sure how to replicate the issue.

      1. If I run the cmdlet Get-PureOneArrayNetworking specifying the array name (Get-PureOneArrayNetworking -arrayName “ArrayName”), I get the following error if there is a filter string being added to the query parameters and I don’t have the square brackets encoded:

        Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
        At C:\Program Files\WindowsPowerShell\Modules\cody.purestorage.pure1\1.4.0.0\Cody.PureStorage.Pure1.psm1:684 char:29
        + … ayNetwork = Invoke-RestMethod -Method Get -Uri $apiendpoint -ContentT …
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

        Also, I’ve noticed that quite often I’ll get this error too:

        Invoke-RestMethod : {“message”:”No authorization provided”}
        At C:\Program Files\WindowsPowerShell\Modules\cody.purestorage.pure1\1.4.0.0\Cody.PureStorage.Pure1.psm1:684 char:29
        + … ayNetwork = Invoke-RestMethod -Method Get -Uri $apiendpoint -ContentT …
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

        That error only occurs sporadically though, and usually will not come up if I run the command again. Caveats: I am behind a corporate proxy.

        1. So I updated the module to URL encode the brackets (v1.4.0.1), so that issue should hopefully go away. The issue wasnt present on my system, so I think it might have to do with something in your network, likely the proxy. The no authorization error is interesting. I suspect the proxy is possibly stripping the header out somehow, or changing it? Regardless, ping me on the code.purestorage Slack team. I would like to know more. I might ask you to open a SR with Pure.

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.