Using the Pure Storage PowerShellSDK2 - Part 1 - Connecting to FlashArray

Welcome to our blog series on using the Pure Storage PowerShell SDK2. In this series, we will provide you with practical insights and examples on how to harness the power of the Pure Storage PowerShell SDK2 to enhance your storage management capabilities.

Throughout this series, we will cover a wide range of topics, including performance data gathering, snapshot management, performance bottleneck identification, and resource management within your FlashArray and Cloud Block Store. I will guide you step by step, making complex tasks easier to understand and execute.

Before we dive into the details, it’s essential to get started on the right foot. In this initial post, we will focus on connecting to your FlashArray and Cloud Block Store, understanding the basic cmdlets, and discovering the functionality and resources available within the Pure Storage PowerShell SDK2 module.

You can find all the supporting code for this blog series at this GitHub Repo.

Let’s Get Started

In this post, we will cover how to get started with the Pure Storage PowerShell SDK2. We’ll cover connecting to your array and learn some basic cmdlets and how to discover what’s in the Pure Storage PowerShell SDK2 module regarding functionality and the resources you can interact with.

The most common way to install the Pure Storage PowerShell SDK2 module is by using Install-Module -Name PureStoragePowerShellSDK2. If you need additional installation methods, such as offline installations, you can find that information here.

Connecting to Your FlashArray

The first thing you’ll want to do is connect to a FlashArray. So, in the code below, you’ll find an example of how to do that. First, I’m building a credential interactively with Get-Credential. This is only one way of doing this. You can also get credentials from Secret Stores and other Key Vaults. The cmdlet Connect-Pfa2Array takes a few parameters -EndPoint, which is the DNS name or IP address of your FlashArray, -Credential, which we just discussed. The only requirement is that it be a PSCredential object. Finally, my FlashArray doesn’t have a trusted certificate installed for HTTPS, so we can add -IgnoreCertificateError to ignore any TLS/SSL errors that will pop up.

After the connection is open, if you output the $FlashArray variable, you’ll see it tells you some basic information about the connection, such as the array name and the API Version. In our connection here, it’s 2.17.

Import-Module PureStoragePowerShellSDK2

$Credential = Get-Credential -UserName "username" -Message 'Enter your credential information...'
$FlashArray = Connect-Pfa2Array –EndPoint flasharray1.example.com -Credential $Credential -IgnoreCertificateError

$FlashArray                                                      

ArrayName                              ApiVersion
---------                              ----------
flasharray1.example.com                2.17

Discovering cmdlets in the Pure Storage PowerShell SDK2 Module

The Pure Storage PowerShell SDK2 has 378 cmdlets covering all array configuration and management dimensions. Using Get-Command -Module PureStoragePowerShellSDK2, you can discover the cmdlets that are available to you. Here’s some example output below.

Get-Command -Module PureStoragePowerShellSDK2


CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Connect-Pfa2Array                                  2.24.70    PureStoragePowerShellSDK2
Cmdlet          Disconnect-Pfa2Array                               2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2ActiveDirectory                            2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2Admin                                      2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2AdminApiToken                              2.24.70    PureStoragePowerShellSDK2

...output omitted

Cmdlet          Update-Pfa2SyslogServerSetting                     2.24.70    PureStoragePowerShellSDK2
Cmdlet          Update-Pfa2VirtualMachine                          2.24.70    PureStoragePowerShellSDK2
Cmdlet          Update-Pfa2Volume                                  2.24.70    PureStoragePowerShellSDK2
Cmdlet          Update-Pfa2VolumeGroup                             2.24.70    PureStoragePowerShellSDK2
Cmdlet          Update-Pfa2VolumeSnapshot                          2.24.70    PureStoragePowerShellSDK2

A core tenant of PowerShell is discovery at the command line, so let’s look at the cmdlets and how we can do that. In the output below, I use Get-Command and filter on the cmdlets that end with the string performance. This is a quick way to find out what our capabilities are. There are cmdlets that will pull performance data for the Array, FA File Directories, HostGroups, Network, Hosts, Pods, VolumeGroups, and Volumes. We’ll be using several of these cmdlets in upcoming posts.

Get-Command -Module PureStoragePowerShellSDK2 | Where-Object { $_.Name -like "*performance" } 

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Get-Pfa2ArrayPerformance                           2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2DirectoryPerformance                       2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2HostGroupPerformance                       2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2HostPerformance                            2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2NetworkInterfacePerformance                2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2PodPerformance                             2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2VolumeGroupPerformance                     2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2VolumePerformance                          2.24.70    PureStoragePowerShellSDK2

Go ahead and change the search string to *Array*, *Directory*, *HostGroup*, *Network*, *Host*, *Pod*, *VolumeGroup*, or *Volume* to discover additional resources you can work with. In the output below, I have an example of all of the cmdlets with the string *Volume* in the cmdlet name…you can see the different operations available for you to work with volumes. We’ll be using several of these cmdlets in upcoming posts as well.

Get-Command -Module  PureStoragePowerShellSDK2 | Where-Object { $_.Name -like "*Volume*" }     

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Get-Pfa2ProtectionGroupVolume                      2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2RemoteVolumeSnapshot                       2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2RemoteVolumeSnapshotTransfer               2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2Volume                                     2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2VolumeDiff                                 2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2VolumeGroup                                2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2VolumeGroupPerformance                     2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2VolumeGroupSpace                           2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2VolumeGroupVolume                          2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2VolumePerformance                          2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2VolumePerformanceByArray                   2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2VolumeProtectionGroup                      2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2VolumeSnapshot                             2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2VolumeSnapshotTags                         2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2VolumeSnapshotTransfer                     2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2VolumeSpace                                2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2VolumeTag                                  2.24.70    PureStoragePowerShellSDK2
Cmdlet          Get-Pfa2VolumeVolumeGroup                          2.24.70    PureStoragePowerShellSDK2
Cmdlet          New-Pfa2ProtectionGroupVolume                      2.24.70    PureStoragePowerShellSDK2
Cmdlet          New-Pfa2RemoteVolumeSnapshot                       2.24.70    PureStoragePowerShellSDK2
Cmdlet          New-Pfa2Volume                                     2.24.70    PureStoragePowerShellSDK2
Cmdlet          New-Pfa2VolumeGroup                                2.24.70    PureStoragePowerShellSDK2
Cmdlet          New-Pfa2VolumeProtectionGroup                      2.24.70    PureStoragePowerShellSDK2
Cmdlet          New-Pfa2VolumeSnapshot                             2.24.70    PureStoragePowerShellSDK2
Cmdlet          Remove-Pfa2ProtectionGroupVolume                   2.24.70    PureStoragePowerShellSDK2
Cmdlet          Remove-Pfa2RemoteVolumeSnapshot                    2.24.70    PureStoragePowerShellSDK2
Cmdlet          Remove-Pfa2Volume                                  2.24.70    PureStoragePowerShellSDK2
Cmdlet          Remove-Pfa2VolumeGroup                             2.24.70    PureStoragePowerShellSDK2
Cmdlet          Remove-Pfa2VolumeProtectionGroup                   2.24.70    PureStoragePowerShellSDK2
Cmdlet          Remove-Pfa2VolumeSnapshot                          2.24.70    PureStoragePowerShellSDK2
Cmdlet          Remove-Pfa2VolumeSnapshotTags                      2.24.70    PureStoragePowerShellSDK2
Cmdlet          Remove-Pfa2VolumeTag                               2.24.70    PureStoragePowerShellSDK2
Cmdlet          Set-Pfa2VolumeSnapshotTagsBatch                    2.24.70    PureStoragePowerShellSDK2
Cmdlet          Set-Pfa2VolumeTagBatch                             2.24.70    PureStoragePowerShellSDK2
Cmdlet          Update-Pfa2RemoteVolumeSnapshot                    2.24.70    PureStoragePowerShellSDK2
Cmdlet          Update-Pfa2Volume                                  2.24.70    PureStoragePowerShellSDK2
Cmdlet          Update-Pfa2VolumeGroup                             2.24.70    PureStoragePowerShellSDK2
Cmdlet          Update-Pfa2VolumeSnapshot                          2.24.70    PureStoragePowerShellSDK2

Gathering Core FlashArray Information

Let’s use some cmdlets to pull some array-level information. First, we can use Get-Pfa2Array to pull some basic information about our FlashArray. This cmdlet shows the Name of the array, its capacity, Purity version, and a Space allocation breakdown.

Get-Pfa2Array -Array $FlashArray -Verbose

Id                 : ac5fc11f-8b3b-49a0-8261-43baf50b281b
Name               : flasharray1.example.com
Banner             : flasharray1.example.com (6.3.11)
Capacity           : 24556000719668
ConsoleLockEnabled : False
Encryption         : @{DataAtRest=@{Algorithm='AES-256-CTR'; Enabled=True}; ModuleVersion='FA-1.3'}
EradicationConfig  : @{EradicationDelay=86400000; ManualEradication='all-enabled'}
IdleTimeout        : 0
NtpServers         : {pool.ntp.org, time.windows.com}
Os                 : Purity//FA
Parity             : 1
ScsiTimeout        : 60000
Space              : @{DataReduction=17.699776; Shared=4820525650909; Snapshots=2815879716020; System=0; ThinProvisioning=0.9444221; 
                     TotalPhysical=13065239325771; TotalProvisioned=3065030876594176; TotalReduction=318.46814; 
                     Unique=5427429194299; Virtual=170347826395136; Replication=1404764543; SharedEffective=36930594904064; 
                     SnapshotsEffective=16050673845760; TotalEffective=74044813160960; UniqueEffective=21063544411136}
Version            : 6.3.14

Accessing Object Property Data

In the output above, you can see the Space information is also an object with additional Properties. I want to show you how to access that information. You must use the -ExpandProperty option to access that data. In the output below, I have an example of that. We will use this technique frequently in this blog series, and you will likely be using this often when working with the data returned from the API.

Get-Pfa2Array -Array $FlashArray | Select-Object Name -ExpandProperty space

Name               : flasharray1.example.com
DataReduction      : 17.69764
Shared             : 4820820869728
Snapshots          : 2815889987767
System             : 0
ThinProvisioning   : 0.9444237
TotalPhysical      : 13065111831175
TotalProvisioned   : 3065030876594176
TotalReduction     : 318.4384
Unique             : 5426997429927
Virtual            : 170343176144896
Replication        : 1403543753
SharedEffective    : 36940174953984
SnapshotsEffective : 16049875705856
TotalEffective     : 74047980740608
UniqueEffective    : 21057930080768
UsedProvisioned    : 

Its All REST Under the Hood

Under the hood, the PowerShell module uses the REST API to communicate with the array. If we add the -Verbose parameter to Get-Pfa2Array, you will see the actual REST call from the client into the REST API. In the output below, the REST Verb is GET, and the URL endpoint is https://flasharray1.example.com/api/2.17/arrays. As you dig deeper into the PowerShell module, things will start getting a little REST-y, I’ll provide you with some resources on that later in this post.

Get-Pfa2Array -Array $FlashArray -Verbose

VERBOSE: PureStorage.Rest Verbose: 13 : 2023-10-04T21:03:08.6650010Z flasharray1.example.com: Get-Pfa2Array (__AllParameterSets) Array=flasharray1.example.com Verbose=True

VERBOSE: PureStorage.Rest Verbose: 10 : 2023-10-04T21:03:08.6652320Z GET https://flasharray1.example.com/api/2.17/arrays <no body>

VERBOSE: PureStorage.Rest Verbose: 11 : 2023-10-04T21:03:09.1754180Z GET https://flasharray1.example.com/api/2.17/arrays 200 510ms {"continuation_token":null,"items":[{"name":"sn1-m70-f06-33","id":"ac5fc11f-8b3b-49a0-8261-43baf50b281b","space":{"data_reduction":17.697636482653046,"shared":4820820869728,"snapshots":2815889987767,"system":0,"thin_provisioning":0.9444236671657353,"total_physical":13065111831175,"total_provisioned":3065030876594176,"total_reduction":318.4383636003751,"unique":5426997429927,"virtual":170343176144896,"unique_effective":21057930080768,"snapshots_effective":16049875705856,"total_effective":74047980740608,"replication":1403543753,"shared_effective":36940174953984},"capacity":24556040984986,"parity":1.0,"eradication_config":{"manual_eradication":"all-enabled","eradication_delay":86400000},"console_lock_enabled":false,"encryption":{"data_at_rest":{"algorithm":"AES-256-CTR","enabled":true},"module_version":"FA-1.3"},"idle_timeout":0,"ntp_servers":["10.21.93.14","pool.ntp.org"],"os":"Purity//FA","scsi_timeout":60000,"version":"6.3.14","banner":"flasharray1.example.com (6.3.11)"}],"more_items_remaining":false,"total_item_count":null}

Wrapping Things Up

In this first installment of our Pure Storage PowerShell SDK2 blog series, we’ve laid the foundation for a productive journey ahead. We’ve shown you how to connect to your FlashArray, introduced you to essential cmdlets, and demonstrated how to discover the extensive functionality available within the Pure Storage PowerShell SDK2 module.

As you continue reading and exploring the subsequent posts in this series, you’ll delve deeper into advanced topics and discover how to perform various tasks efficiently. We encourage you to refer to the provided resources and join our community to enhance your knowledge and maximize the benefits of the Pure Storage PowerShell SDK2.

Remember, this series is designed to simplify complex storage management tasks and empower you to make the most of your Pure Storage environment. Stay tuned for more valuable insights and practical examples in the upcoming posts. Your journey to becoming a Pure Storage expert begins here.

Additional Resources

  • First, the module has a GitHub repository. Here, you can open issues and interact with the project.
  • Second, this is a link to a hub for all our Code integrations at code.purestorage.com
    • Most importantly, in the upper right-hand corner is a Slack icon where you can join our Code.PureStorage.Com Slack community and interact with Pure employees and other community members.
  • Next, here’s a link to our REST API Reference.
    • As you dig deeper into the PowerShell module, things will start getting a little REST-y, and having these docs handy will help you be able to implement more complex tasks.
  • Finally, here’s a link to the hub for all our Knowledge Base articles and additional code examples for the Pure Storage PowerShell SDK2 module.

Pure Storage PowerShell SDK2 Blog Series

This article is part of a blog series covering the Pure Storage PowerShell SDK2. Check out the other posts in this series:

You can find the supporting code for this blog series at this GitHub Repo and you can watch a webinar Unlocking the Full Potential of Pure Storage with APIs which has a walk-through of all of these demos.

code.purestorage.com