2
2
Example PowerShell scripts for the Pure Storage PowerShell SDK
3
3
This contains the step-by-step example script that follows along with the Quick Start Guide (https://support.purestorage.com/Solutions/Microsoft_Platform_Guide/a_Windows_PowerShell) as well as some further examples to help you create your own scripts using the SDK.
4
4
5
- This script is AS-IS. No warranties expressed or implied by Pure Storage or the creator .
5
+ These examples are presented AS-IS. No warranties expressed or implied by Pure Storage or the creators .
6
6
7
7
: REVISION HISTORY
8
8
:: 04.23.2021 - Fixed the -Credential parameter from plural to singular
@@ -20,12 +20,16 @@ This script is AS-IS. No warranties expressed or implied by Pure Storage or the
20
20
# Basic PowerShell routines to see the cmdlets available, updating Help, and getting various degrees of Help
21
21
Get-Module - ListAvailable
22
22
$env: PSModulePath
23
+
23
24
# All of the available cmdlets in the module
24
25
Get-Command - Module PureStoragePowerShellSDK2
26
+
25
27
# How many cmdlets are available in the module
26
28
(Get-Command - Module PureStoragePowerShellSDK2).Count
29
+
27
30
# Periodically, the Help should be updated for all PowerShell modules. This does require PowerShell be "Run as Administrator".
28
31
Update-Help - Module PureStoragePowerShellSDK2
32
+
29
33
# All the variations of Help available for cmdlets
30
34
Get-Help New-Pfa2Array
31
35
Get-Help New-Pfa2Array - Full
@@ -37,7 +41,7 @@ Get-Help New-Pfa2Array -Examples
37
41
<#
38
42
Connecting to the FlashArray
39
43
40
- There are a couple of ways to connect to the FlashArray - via API Tokens or OAuth2. OAuth2 is more secure, but also a bit more complex.
44
+ There are a few ways to connect to the FlashArray - via API Tokens or OAuth2. OAuth2 is more secure, but also a bit more complex.
41
45
To see all of the ways to authenticate to an array with the SDK, inclusing with OAuth2, please see this article -
42
46
https://support.purestorage.com/Solutions/Microsoft_Platform_Guide/a_Windows_PowerShell/How-To%3A_Connect_to_FlashArray_with_SDK_v12x
43
47
@@ -50,112 +54,164 @@ https://<FQDN or IP Address of Array>/api/api_version
50
54
51
55
# For these examples, we will do a simple API Token exchange.
52
56
$Creds = Get-Credential
53
- # Change the <IP/FQDN> to match your array
54
- $FlashArray = Connect-Pfa2Array - EndPoint < IP/ FQDN> - Credential $Creds - IgnoreCertificateError
57
+
58
+ # Change the EndPopint IP/FQDN to match your array
59
+ $FlashArray = Connect-Pfa2Array - EndPoint 192.0 .0.1 - Credential $Creds - IgnoreCertificateError
60
+
55
61
# Once connected, run a few commands to verify connectivity
56
62
Get-Pfa2Controller - Array $FlashArray
57
- $Controllers = Get-Pfa2Controller – Array $FlashArray
63
+ $Controllers = Get-Pfa2Controller - Array $FlashArray
58
64
$Controllers
59
65
60
66
# # Working with Volumes
61
67
# ######################
68
+
62
69
# Create a new volume that is 200GB in size and just to see what's happening, turn on the -Verbose parameter
63
- New-Pfa2Volume - Array $FlashArray - Name ' SDKv2-Sample' - Provisioned 214748364800 - Verbose
70
+ New-Pfa2Volume - Array $FlashArray - Name " SDKv2-Sample" - Provisioned 214748364800 - Verbose
71
+
64
72
# Create 5 volumes, all 200GB in size
65
73
ForEach ($i in 1 .. 5 ) { New-Pfa2Volume - Array $FlashArray - Name " SDKv2-TestSample-$i " - Provisioned 214748364800 }
74
+
66
75
# View the volumes after creation
67
- Get-Pfa2Volume - Array $FlashArray - Name ' SDKv2-TestSample-3' | Format-Table –Autosize
68
- Get-Pfa2Volume - Array $FlashArray | Where-Object { $_.name -like ' SDKv2-TestSample*' } | Format-Table - AutoSize
76
+ Get-Pfa2Volume - Array $FlashArray - Name " SDKv2-TestSample-3" | Format-Table - Autosize
77
+ Get-Pfa2Volume - Array $FlashArray | Where-Object { $_.name -like " SDKv2-TestSample*" } | Format-Table - AutoSize
78
+
69
79
# Change the name of a volume
70
- Update-Pfa2Volume - Array $FlashArray - Name ' SDKv2-TestSample-5' - VolumeName ' SDKv2-TestSample-500'
80
+ Update-Pfa2Volume - Array $FlashArray - Name " SDKv2-TestSample-5" - VolumeName " SDKv2-TestSample-500"
81
+
71
82
# Create a volume using the CLI via SSH
72
83
$CommandText = " purevol create --size 10G DEMO-VOL10"
73
84
Invoke-Pfa2CLICommand - EndPoint $ArrayEndpoint - Username $ArrayUsername - Password $ArrayPassword - CommandText $CommandText
74
85
86
+ # Use PowerShell built-in math functionaility to do data size conversions to bytes. You can see this from the PowerShell prompt by simply typing "1tb".
87
+ <# This allows for some cmdlets that have a -Provisioned or -Size type parameter to use the simplier value and have it converted to the required value automagically.
88
+ Example: The New-Pfa2Volume cmdlet requires a -Provisioned parameter value that is in bytes. By specifying the conversion value, it is automaticallyconverted to bytes by PowerShell.
89
+ #>
90
+ New-Pfa2Volume - Name DemoVol - Provisioned 100 gb
91
+ <# The result is:
92
+ Space : class Space {
93
+ TotalProvisioned: 107374182400
94
+ }
95
+ #>
96
+
75
97
# # Volume and Host Connections
76
98
# #############################
99
+
77
100
# Define some (fake) WWNs and create a host
78
- $wwn = @ (' 10:00:00:00:00:00:11:11' , ' 10:00:00:00:00:00:12:12' )
79
- New-Pfa2Host –Array $FlashArray –Name ‘ SDKv2-host’ –WwnList $wwn
101
+ $wwn = @ (" 10:00:00:00:00:00:11:11" , " 10:00:00:00:00:00:12:12" )
102
+ New-Pfa2Host - Array $FlashArray - Name " SDKv2-host" - WwnList $wwn
103
+
80
104
# Do the same for iSCSI Iqns
81
- $iqn = @ (' iqn.1998-01.com.sample1.iscsi' , ' iqn.1998-01.com.sample2.iscsi' )
82
- New-Pfa2Host - Array $FlashArray - Name ' SDK2-IQNS-host' - Iqns $iqn
105
+ $iqn = @ (" iqn.1998-01.com.sample1.iscsi" , " iqn.1998-01.com.sample2.iscsi" )
106
+ New-Pfa2Host - Array $FlashArray - Name " SDK2-IQNS-host" - Iqns $iqn
107
+
83
108
# Create a new Host Group
84
- New-Pfa2HostGroup - Array $FlashArray - Name ' SDKv2-HostGroup'
109
+ New-Pfa2HostGroup - Array $FlashArray - Name " SDKv2-HostGroup"
110
+
85
111
# Add a host to the group
86
- New-Pfa2HostGroupHost - GroupNames ' SDKv2-HostGroup' - MemberNames ' TEST-HOST1'
112
+ New-Pfa2HostGroupHost - GroupNames " SDKv2-HostGroup" - MemberNames " SDKv1-HOST1"
113
+
87
114
# Retrieve a volume and connect it to the host & host group
88
- Get-Pfa2Volume - Array $FlashArray | Where-Object { $_.name -like ' SDK*' } | Format-Table - AutoSize
89
- New-Pfa2Connection - Array $FlashArray - VolumeNames ' SDKv2-Sample-2' - HostNames ' SDKv2-host'
90
- New-Pfa2Connection - Array $FlashArray - VolumeNames ' SDKv2-Sample-2' - HostGroupNames ' SDKv2-HostGroup'
115
+ Get-Pfa2Volume - Array $FlashArray | Where-Object { $_.name -like " SDK*" } | Format-Table - AutoSize
116
+ New-Pfa2Connection - Array $FlashArray - VolumeNames " SDKv2-Sample-2" - HostNames " SDKv2-host"
117
+ New-Pfa2Connection - Array $FlashArray - VolumeNames " SDKv2-Sample-2" - HostGroupNames " SDKv2-HostGroup"
118
+
91
119
# Remove the volume from the host group
92
- Remove-Pfa2Connection - Array $FlashArray - VolumeNames ' SDKv2-Sample-2' - HostGroupNames ' SDKv2-HostGroup'
120
+ Remove-Pfa2Connection - Array $FlashArray - VolumeNames " SDKv2-Sample-2" - HostGroupNames " SDKv2-HostGroup"
93
121
94
122
# # FlashRecover Snapshots
95
123
# ########################
124
+
96
125
# Create snapshots, view them, and copy a snapshot to a new volume
97
- New-Pfa2VolumeSnapshot - Array $FlashArray - SourceNames ' SDKv2-sample-1' , ' SDKv2-sample-2' - Suffix ' EXAMPLE'
98
- Get-Pfa2VolumeSnapshot - Name ' SDKv2-sample-1.EXAMPLE'
99
- $src = New-Pfa2ReferenceObject - Id < returned snapshot ID > - Name < returned snapshot name >
126
+ New-Pfa2VolumeSnapshot - Array $FlashArray - SourceNames " SDKv2-sample-1" , " SDKv2-sample-2" - Suffix " EXAMPLE"
127
+ $snap = Get-Pfa2VolumeSnapshot - Name " SDKv2-sample-1.EXAMPLE"
128
+ $src = New-Pfa2ReferenceObject - Id $snap .Id - Name $snap .Name
100
129
New-Pfa2Volume - Name volumecopy - Source $src
101
130
102
131
# # Protection Groups
103
132
# ###################
133
+
104
134
# Create a Protection group
105
- New-Pfa2ProtectionGroup - Array $FlashArray - Name ' SDKv2-PGROUP'
135
+ New-Pfa2ProtectionGroup - Array $FlashArray - Name " SDKv2-PGROUP"
136
+
106
137
# Create a new volume
107
- New-Pfa2Volume - Name ' SDKv2-VOL1' - Provisioned 10485760
138
+ New-Pfa2Volume - Name " SDKv2-VOL1" - Provisioned 10485760
139
+
108
140
# Add the volume to the Protection Group
109
- New-Pfa2ProtectionGroupVolume - GroupNames ' SDKv2-PGROUP' - MemberNames ' SDKv2-VOL1'
141
+ New-Pfa2ProtectionGroupVolume - GroupNames " SDK-PGROUP" - MemberNames " SDK-VOL1"
142
+
110
143
# Snapshot the volume
111
- New-Pfa2ProtectionGroupSnapshot - Array $FlashArray - SourceNames ' SDKv2-PGROUP' - Suffix ' EXAMPLE'
144
+ New-Pfa2ProtectionGroupSnapshot - Array $FlashArray - SourceNames " SDK-PGROUP" - Suffix " EXAMPLE"
145
+
112
146
# Set the snapshot schedule for the Protection Group
113
- Get-Pfa2ProtectionGroupSnapshot - Array $FlashArray - Name ' SDKv2 -PGROUP'
114
- $schedule = Get-Pfa2ProtectionGroup - Array $FlashArray - Name ' SDKv2 -PGROUP'
147
+ Get-Pfa2ProtectionGroupSnapshot - Array $FlashArray - Name " SDK -PGROUP"
148
+ $schedule = Get-Pfa2ProtectionGroup - Array $FlashArray - Name " SDK -PGROUP"
115
149
$schedule.SnapshotSchedule
116
150
$snapschedule = New-Pfa2SnapshotScheduleObject - At 7200000 - Enabled $false - Frequency 259200000
117
- Update-Pfa2ProtectionGroup - Name ' SDKv2-PGROUP' - SnapshotSchedule $snapschedule
151
+ Update-Pfa2ProtectionGroup - Name " SDK-PGROUP" - SnapshotSchedule $snapschedule
152
+
118
153
# Remove the Protection Group
119
- Remove-Pfa2VolumeProtectionGroup - Array $FlashArray - MemberNames ' SDKv2-VOL1' - GroupNames ' SDKv2-PGROUP'
154
+ Remove-Pfa2VolumeProtectionGroup - Array $FlashArray - MemberNames " SDK-VOL1" - GroupNames " SDK-PGROUP"
155
+
120
156
# Add a host to a Protection Group
121
- New-Pfa2ProtectionGroupHost - Array $FlashArray - GroupNames ' SDKv2-PGROUP' - Membernames ' SDKv2-HOST'
157
+ New-Pfa2ProtectionGroupHost - Array $FlashArray - GroupNames " SDK-PGROUP" - Membernames " SDK-HOST"
158
+
122
159
# Create a snapshot
123
- New-Pfa2ProtectionGroupSnapshot - Array $FlashArray - SourceNames ' SDKv2-PGROUP'
160
+ New-Pfa2ProtectionGroupSnapshot - Array $FlashArray - SourceNames " SDK-PGROUP"
161
+
124
162
# Remove the host
125
- Remove-Pfa2ProtectionGroupHost - Array $FlashArray - MemberNames ' SDKv2-HOST' - GroupNames ' SDKv2-PGROUP'
163
+ Remove-Pfa2ProtectionGroupHost - Array $FlashArray - MemberNames " SDK-HOST" - GroupNames " SDK-PGROUP"
164
+
126
165
# Create a new Host Protection Group
127
- New-Pfa2HostGroupsProtectionGroup - Array $FlashArray - MemberNames ' SDKv2-HOSTGROUP' - GroupNames ' SDKv2-PGROUP'
166
+ New-Pfa2HostGroupsProtectionGroup - Array $FlashArray - MemberNames " SDK-HOSTGROUP" - GroupNames " SDK-PGROUP"
167
+
128
168
# Create a snapshot of the group
129
- New-Pfa2ProtectionGroupSnapshot - Array $FlashArray - SourceNames ' SDKv2-PGROUP'
169
+ New-Pfa2ProtectionGroupSnapshot - Array $FlashArray - SourceNames " SDK-PGROUP"
170
+
171
+ # Alternative via the CLI with ReplicateNow
172
+ $CommandText = " purepgroup snap --replicate-now SDK-PGROUP"
173
+ Invoke-Pfa2CLICommand - EndPoint array1 - Credential (Get-Credential ) - IgnoreCertificateError - CommandText $CommandText
130
174
131
175
# # Performance and Space Metrics
132
176
# ###############################
133
177
# These are just a small sample of many performance and metric cmdlets available in the SDK.
178
+
134
179
# This example will retrieve all of the cmdlets that have Performance in the name, and then run a few Array performance commands outputting in different formats
135
180
Get-Command - Module PureStoragePowerShellSDK2 * Performance*
136
- Get-Pfa2ArrayPerformance - Array $FlashArray - endtime ' 2020-08-07T01:00:00Z' - starttime ' 2020-08-06T01:00:00Z' - resolution 28800000
137
- Get-Pfa2ArrayPerformance - Array $FlashArray - endtime ' 2020-08-07T01:00:00Z' - starttime ' 2020-08-06T01:00:00Z' - resolution 28800000 | Format-Table –AutoSize
138
- Get-Pfa2ArrayPerformance - Array $FlashArray - endtime ' 2020-08-07T01:00:00Z' - starttime ' 2020-08-06T01:00:00Z' - resolution 28800000 | Export-Csv - Path ‘ C:\temp\test.csv’
139
- Get-Pfa2ArraySpace - Array $FlashArray - endtime ' 2020-08-07T01:00:00Z' - starttime ' 2020-08-06T01:00:00Z' - resolution 28800000
181
+ Get-Pfa2ArrayPerformance - Array $FlashArray - endtime " 2020-08-07T01:00:00Z" - starttime " 2020-08-06T01:00:00Z" - resolution 28800000
182
+ Get-Pfa2ArrayPerformance - Array $FlashArray - endtime " 2020-08-07T01:00:00Z" - starttime " 2020-08-06T01:00:00Z" - resolution 28800000 | Format-Table –AutoSize
183
+ Get-Pfa2ArrayPerformance - Array $FlashArray - endtime " 2020-08-07T01:00:00Z" - starttime " 2020-08-06T01:00:00Z" - resolution 28800000 | Export-Csv - Path " C:\temp\test.csv"
184
+ Get-Pfa2ArraySpace - Array $FlashArray - endtime " 2020-08-07T01:00:00Z" - starttime " 2020-08-06T01:00:00Z" - resolution 28800000
140
185
141
186
# # Logging
142
187
# #########
188
+
143
189
# Start SDK logging to a file calles session.log in the current folder
144
190
Set-Pfa2Logging - LogFilename session.log
191
+
145
192
# You could now open a new PowerShell session and use the Get-Content cmdlet to view that file as it is written to
146
193
Get-Content session.log - Wait
147
194
148
195
149
196
# # Pipeline examples
150
197
# ###################
198
+
199
+ # Create a PowerShell array of authenticated FlashArray objects and perform a command against all of the objects in series
200
+ $flasharray @ ()
201
+ $flasharray += Connect-Pfa2Array - Endpoint array1 - Credential (Get-Credential ) - IgnoreCertificateError
202
+ $flasharray += Connect-Pfa2Array - Endpoint array2 - Credential (Get-Credential ) - IgnoreCertificateError
203
+ $flasharray += Connect-Pfa2Array - Endpoint array3 - Credential (Get-Credential ) - IgnoreCertificateError
204
+ $flasharray += Connect-Pfa2Array - Endpoint array4 - Credential (Get-Credential ) - IgnoreCertificateError
205
+ Get-Pfa2Volume - Array $flasharray
206
+
151
207
# Remove all of existing hosts
152
208
Get-Pfa2Host - Array $FlashArray | Remove-Pfa2Host - Array $FlashArray
153
209
154
210
# Remove all hosts containing "test" in name
155
- (Get-Pfa2host - Array $FlashArray ) | Where-Object { $_.name -like ' *test*' } | Remove-Pfa2Host - Array $FlashArray
211
+ (Get-Pfa2host - Array $FlashArray ) | Where-Object { $_.name -like " *test*" } | Remove-Pfa2Host - Array $FlashArray
156
212
157
213
# Filter hosts and remove. Change name as fit.
158
- Get-Pfa2Host - Array $FlashArray | Where-Object { $_.name -eq ' a-test1' } | Remove-Pfa2Host - Array $FlashArray
214
+ Get-Pfa2Host - Array $FlashArray | Where-Object { $_.name -eq " a-test1" } | Remove-Pfa2Host - Array $FlashArray
159
215
160
216
# # Retrive formatted Volume info
161
217
Get-Pfa2Volumes - Array $FlashArray | Format-Table - AutoSize
@@ -172,7 +228,7 @@ Get-Pfa2Volume -Array $FlashArray | Where-Object { $_.Name -like $VolName } -Des
172
228
Get-Pfa2Volume | Update-Pfa2Volume - Destroyed $True
173
229
174
230
# Destroy (delete) volumes
175
- Get-Pfa2Volume - Array $FlashArray - Filter " name=' vol1' " - Destroyed $False | Update-Pfa2Volume - Array $FlashArray - Destroyed $True
231
+ Get-Pfa2Volume - Array $FlashArray - Filter - name= " vol1" - Destroyed $False | Update-Pfa2Volume - Array $FlashArray - Destroyed $True
176
232
177
233
# Query volumes to test for Destroy success
178
234
$Volume = Get-Pfa2Volume - Array $FlashArray | Where-Object { $_.Name -like $VolName } - Destroyed $True
@@ -186,13 +242,14 @@ Get-Pfa2VolumeSnapshot -Array $FlashArray | Where-Object { $_.Suffix -eq "JustAD
186
242
187
243
# # Miscellaneous
188
244
# ###############
245
+
189
246
# Use Invoke method to pass CLI command
190
- $CommandText = " purevol create --size 10G test -volume-name"
247
+ $CommandText = " purevol create --size 10G SDK -volume-name"
191
248
Invoke-Pfa2CLICommand - EndPoint $FlashArray - Username $FlashArrayUsername - Password $FlashArrayPassword - CommandText $CommandText
192
249
193
250
# Get snapshot information, create reference pbject, & create new volume from snapshot
194
- Get-Pfa2VolumeSnapshot - Name test-volume .testSnap. test1
195
- $src = New-Pfa2ReferenceObject - Id < returned snapshot ID > - Name < returned snapshot name >
251
+ $snap = Get-Pfa2VolumeSnapshot - Name test1
252
+ $src = New-Pfa2ReferenceObject - Id $snap .Id - Name $snap .Name
196
253
New-Pfa2Volume - Name volumecopy - Source $src
197
254
198
255
# Query volumes to test for eradication success
0 commit comments