-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPureStorage.FlashArray.VMware.Software.psm1
1594 lines (1495 loc) · 59.2 KB
/
PureStorage.FlashArray.VMware.Software.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function Install-PfavSpherePlugin {
<#
.SYNOPSIS
Installs or updates the FlashArray vSphere Plugin
.DESCRIPTION
Install or updates the vSphere Plugin, HTML or Flash version.
.INPUTS
A plugin download source (FlashArray or Pure1), plugin type, or version.
.OUTPUTS
Returns registered extension.
.EXAMPLE
PS C:\ Install-PfavSpherePlugin
Installs the latest appropriate plugin (flash or HTML) located on Pure1 to the connected vCenter
.EXAMPLE
PS C:\ Install-PfavSpherePlugin -confirm:$false
Installs the latest appropriate plugin (flash or HTML) located on Pure1 to the connected vCenter without prompting for confirmation
.EXAMPLE
PS C:\ Install-PfavSpherePlugin -flash -version 3.1.2
Installs the Flash 3.1.2 plugin located on Pure1 to the connected vCenter.
.EXAMPLE
PS C:\ $fa = new-pfaconnection -endpoint flasharray-m20-1.purecloud.com -credentials (get-credential) -DefaultArray
PS C:\ Install-PfavSpherePlugin -flasharray $fa
Installs the plugin that is hosted on the specified FlashArray to the connected vCenter.
.NOTES
Version: 2.0
Author: Cody Hosterman https://codyhosterman.com
Creation Date: 01/04/2020
Purpose/Change: Added parameter sets and validation
*******Disclaimer:******************************************************
This scripts are offered "as is" with no warranty. While this
scripts is tested and working in my environment, it is recommended that you test
this script in a test lab before using in a production environment. Everyone can
use the scripts/commands provided here without any written permission but I
will not be liable for any damage or loss to the system.
************************************************************************
#>
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='High',DefaultParameterSetName='Version')]
Param(
[Parameter(Position=0,ValueFromPipeline=$True,ParameterSetName='FA')]
[PurePowerShell.PureArray]$flasharray,
[Parameter(ParameterSetName='HTML',Position=1)]
[switch]$html,
[Parameter(ParameterSetName='Flash',Position=2)]
[switch]$flash,
[ValidateScript({
if ($_ -match '[0-9]+\.[0-9]+\.[0-9]+$')
{
$true
}
else {
throw "The version must be in the format of x.x.x. Like 4.2.0 or 3.1.3."
}
})]
[Parameter(ParameterSetName='HTML',Position=3)]
[Parameter(ParameterSetName='Flash',Position=3)]
[Parameter(ParameterSetName='Version',Position=3)]
[string]$version
)
$ErrorActionPreference = "Stop"
if ($null -eq $global:defaultviserver)
{
throw "There is no PowerCLI connection to a vCenter, please connect first with connect-viserver."
}
if ($null -eq $flasharray)
{
$pure1 = $true
}
else {
$pure1 = $false
}
####Check vCenter versions and plugin version compatibility
$vCenterVersion = ($global:DefaultVIServer | Select-Object Version).version
if ($vCenterVersion.split(".")[0] -eq 5)
{
throw "This cmdlet does not support vCenter 5.x"
}
if (($html -eq $false) -and ($flash -eq $false))
{
if (($vCenterVersion.split(".")[1] -eq 0) -and ($vCenterVersion.split(".")[0] -eq 6))
{
$flash = $true
}
else {
$html = $true
}
}
if ($html -eq $true)
{
if (($vCenterVersion.split(".")[1] -eq 0) -and ($vCenterVersion.split(".")[0] -eq 6))
{
throw "The specified version of the plugin (HTML) does not support vCenter 6.0. 6.5 and later only."
}
}
if (($version -match '3\.[0-9]+\.[0-9]+$'))
{
$flash = $true
if ($html -eq $true)
{
throw "The specified version $($version) is not a valid version for the HTML plugin. Must be 4.x.x or higher."
}
}
if (($version -match '4\.[0-9]+\.[0-9]+$'))
{
$html = $true
if ($flash -eq $true)
{
throw "The specified version $($version) is not a valid version for the flash plugin. Must be 3.x.x or lower."
}
}
#find source address
if ($null -ne $flasharray)
{
$ipAddress = (Get-PfaNetworkInterface -Array $flasharray -Name vir0).address
}
else
{
if ($flash -eq $true)
{
$ipAddress = "https://pure-vmware-plugin-repository.s3-us-west-1.amazonaws.com/vsphere/Flex/purestorage-vsphere-plugin.zip"
}
else
{
$ipAddress = "https://pure-vmware-plugin-repository.s3-us-west-1.amazonaws.com/vsphere/HTML5/purestorage-vsphere-plugin.zip"
}
}
#gather extension manager
$services = Get-view 'ServiceInstance'
$extensionMgr = Get-view $services.Content.ExtensionManager
#find what plugins are installed and their version
$installedHtmlVersion = ($extensionMgr.FindExtension("com.purestorage.purestoragehtml")).version
$installedFlashVersion = ($extensionMgr.FindExtension("com.purestorage.plugin.vsphere")).version
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
#identify available plugin versions.
$global:pfavSpherePluginUrl = $true
if ($pure1 -eq $true)
{
if (!([string]::IsNullOrWhiteSpace($version)))
{
$fullPluginInfo = Get-PfavSpherePlugin -version $version -html:$html -flash:$flash -previous
}
else {
$fullPluginInfo = Get-PfavSpherePlugin -html:$html -flash:$flash
}
}
else {
$fullPluginInfo = Get-PfavSpherePlugin -flasharray $flasharray -skipPure1
}
if ($null -eq $fullPluginInfo)
{
throw "Specified plugin type or version not found on available source"
}
if ($fullPluginInfo.count -gt 1)
{
throw "Too many plugin versions returned. Internal script error!"
}
$hostedVersion = $fullPluginInfo.version
$global:pfavSpherePluginUrl = $null
#find out what plugin will be installed and whether it is an upgrade. Will fail if newer version is on vCenter
$upgrade = $false
if ($hostedVersion.split(".")[0] -ge 4)
{
if ($null -ne $installedHtmlVersion)
{
$splitInstalled = $installedHtmlVersion.split(".")
$splitHosted = $hostedVersion.split(".")
if ($splitInstalled[0] -eq $splitHosted[0])
{
if ($splitInstalled[1] -eq $splitHosted[1])
{
if ($splitInstalled[2] -lt $splitHosted[2])
{
$upgrade = $true
}
elseif ($splitInstalled[2] -eq $splitHosted[2])
{
throw "The installed version of the plugin ($($installedHtmlVersion)) is the same as the version on the specified source ($($hostedVersion))"
}
elseif ($splitInstalled[2] -gt $splitHosted[2])
{
throw "The installed version of the plugin ($($installedHtmlVersion)) is newer than the version on the specified source ($($hostedVersion))"
}
}
elseif ($splitInstalled[1] -lt $splitHosted[1])
{
$upgrade = $true
}
else {
throw "The installed version of the plugin ($($installedHtmlVersion)) is newer than the version on the specified source ($($hostedVersion))"
}
}
elseif ($splitInstalled[0] -lt $splitHosted[0])
{
$upgrade = $true
}
else {
throw "The installed version of the plugin ($($installedHtmlVersion)) is newer than the version on the specified source ($($hostedVersion))"
}
}
}
elseif ($hostedVersion.split(".")[0] -eq 3)
{
if ($null -ne $installedFlashVersion)
{
$splitInstalled = $installedFlashVersion.split(".")
$splitHosted = $hostedVersion.split(".")
if ($splitInstalled[0] -eq $splitHosted[0])
{
if ($splitInstalled[1] -eq $splitHosted[1])
{
if ($splitInstalled[2] -lt $splitHosted[2])
{
$upgrade = $true
}
elseif ($splitInstalled[2] -eq $splitHosted[2])
{
throw "The installed version of the plugin ($($installedFlashVersion)) is the same as the version on the specified source ($($hostedVersion))"
}
elseif ($splitInstalled[2] -gt $splitHosted[2])
{
throw "The installed version of the plugin ($($installedFlashVersion)) is newer than the version on the specified source ($($hostedVersion))"
}
}
elseif ($splitInstalled[1] -lt $splitHosted[1])
{
$upgrade = $true
}
else {
throw "The installed version of the plugin ($($installedFlashVersion)) is newer than the version on the specified source ($($hostedVersion))"
}
}
elseif ($splitInstalled[0] -lt $splitHosted[0])
{
$upgrade = $true
}
else {
throw "The installed version of the plugin ($($installedFlashVersion)) is newer than the version on the specified source ($($hostedVersion))"
}
}
}
#build extension to register. Will pull the SSL thumprint from the target address
$description = New-Object VMware.Vim.Description
$description.label = "Pure Storage Plugin"
$description.summary = "Pure Storage vSphere Plugin for Managing FlashArray"
$extensionClientInfo = New-Object VMware.Vim.ExtensionClientInfo
$extensionClientInfo.Company = "Pure Storage, Inc."
$extensionClientInfo.Description = $description
$extensionClientInfo.Type = "vsphere-client-serenity"
$extensionClientInfo.Url = $fullPluginInfo.URL
$extensionClientInfo.Version = $hostedVersion
$extensionServerInfo = New-Object VMware.Vim.ExtensionServerInfo
$extensionServerInfo.AdminEmail = "[email protected]"
$extensionServerInfo.Company = "Pure Storage, Inc."
$extensionServerInfo.Description = $description
$extensionServerInfo.Url = $fullPluginInfo.URL
if ($pure1 -eq $true)
{
$extensionServerInfo.ServerThumbprint = (Get-SSLThumbprint $fullPluginInfo.URL)
}
else
{
$extensionServerInfo.ServerThumbprint = (Get-SSLThumbprint "https://$($ipAddress)")
}
$extensionServerInfo.Type = "https"
$extensionSpec = New-Object VMware.Vim.Extension
if ($hostedVersion.split(".")[0] -eq 3)
{
$extensionSpec.key = "com.purestorage.plugin.vsphere"
$pluginType = "Flash"
$pluginVersion = $installedFlashVersion
}
else
{
$extensionSpec.key = "com.purestorage.purestoragehtml"
$pluginType = "HTML-5"
$pluginVersion = $installedHtmlVersion
}
$extensionSpec.version = $hostedVersion
$extensionSpec.Description = $description
$extensionSpec.Client += $extensionClientInfo
$extensionSpec.Server += $extensionServerInfo
$extensionSpec.LastHeartbeatTime = get-date
if ($pure1 -eq $false)
{
$source = $ipAddress
}
else {
$source = "Pure1"
}
if ($upgrade -eq $true)
{
$confirmText = "Upgrade $($pluginType) plugin from version $($pluginVersion) to $($hostedVersion) on vCenter $($global:DefaultVIServer.name)?"
}
else {
$confirmText = "Install $($pluginType) plugin version $($hostedVersion) on vCenter $($global:DefaultVIServer.name)?"
}
if ($PSCmdlet.ShouldProcess("","$($confirmText)`n`r","Using $($source) as the download location`n`r"))
{
#install or upgrade the vSphere plugin
if ($upgrade -eq $true)
{
$extensionMgr.UpdateExtension($extensionSpec)
}
else
{
$extensionMgr.RegisterExtension($extensionSpec)
}
return $extensionMgr.FindExtension($extensionSpec.Key)
}
}
function Get-PfavSpherePlugin {
<#
.SYNOPSIS
Retrieves version of FlashArray vSphere Plugin on one or more FlashArrays
.DESCRIPTION
Retrieves version of FlashArray vSphere Plugin on one or more FlashArrays
.INPUTS
One or more FlashArray connections
.OUTPUTS
Returns plugin version for each array and/or Pure1.
.EXAMPLE
PS C:\ Get-PfavSpherePlugin
Retrieves the latest vSphere plugin versions available on Pure1.
.EXAMPLE
PS C:\ Get-PfavSpherePlugin -previous
Retrieves all of the vSphere plugin versions (old and latest) available on Pure1.
.EXAMPLE
PS C:\ $fa = new-pfaarray -endpoint flasharray-m20-1 -credentials (get-credential) -ignoreCertificateError
PS C:\ Get-PfavSpherePlugin -FlashArray $fa
Retrieves the vSphere plugin version from the target FlashArray connection and Pure1.
.EXAMPLE
PS C:\ new-pfaconnection -endpoint flasharray-m20-1 -credentials (get-credential) -ignoreCertificateError -nonDefaultArray
PS C:\ new-pfaconnection -endpoint flasharray-420-1 -credentials (get-credential) -ignoreCertificateError -nonDefaultArray
PS C:\ Get-PfavSpherePlugin
Retrieves the vSphere plugin version from the FlashArray connections stored in the global variable $Global:AllFlashArrays and Pure1.
.EXAMPLE
PS C:\ $fa = new-pfaarray -endpoint flasharray-m20-1 -credentials (get-credential) -ignoreCertificateError
PS C:\ Get-PfavSpherePlugin -FlashArray $fa -skipPure1
Retrieves the vSphere plugin version from the target FlashArray connection and does NOT query Pure1.
.NOTES
Version: 2.0
Author: Cody Hosterman https://codyhosterman.com
Creation Date: 01/04/2020
Purpose/Change: Parameter validation.
*******Disclaimer:******************************************************
This scripts are offered "as is" with no warranty. While this
scripts is tested and working in my environment, it is recommended that you test
this script in a test lab before using in a production environment. Everyone can
use the scripts/commands provided here without any written permission but I
will not be liable for any damage or loss to the system.
************************************************************************
#>
[CmdletBinding(DefaultParameterSetName='Pure1')]
Param(
[Parameter(Position=0,ValueFromPipeline=$True)]
[PurePowerShell.PureArray[]]$flasharray,
[Parameter(Position=1,ParameterSetName='SkipPure1')]
[switch]$skipPure1,
[Parameter(Position=2)]
[switch]$html,
[Parameter(Position=3)]
[switch]$flash,
[Parameter(Position=4)]
[string]$version,
[Parameter(Position=5,ParameterSetName='Pure1')]
[switch]$previous
)
if ($flasharray.count -eq 0)
{
$flasharray = $Global:AllFlashArrays
if (($flasharray.count -eq 0) -and ($skipPure1 -eq $True))
{
throw "You must either enter a FlashArray connection and/or not specify -skipPure1."
}
}
#identify version of the plugin on the array
$targetAddresses = @()
foreach ($fa in $flasharray)
{
$ipAddress = (Get-PfaNetworkInterface -Array $fa -Name vir0).address
try {
$targetAddresses += ([system.net.dns]::GetHostByAddress($ipAddress)).HostName
}
catch {
$targetAddresses += $ipAddress
}
}
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
$identifiedArrays = @()
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$hostedVersions = @()
$hostedVersionUrls = @()
foreach ($targetAddress in $targetAddresses)
{
$hostedVersion = $null
if ([string]::IsNullOrWhiteSpace($version))
{
for ($major=0; $major -le 4; $major++)
{
if ($null -ne $hostedVersion)
{
break
}
for ($minor=0; $minor -le 3; $minor++)
{
$HTTP_Request = [System.Net.WebRequest]::Create("https://$($targetAddress)/download/purestorage-vsphere-plugin.zip?version=4.$($major).$($minor)")
try {
$HTTP_Response = $null
$HTTP_Request.Timeout = 500
$HTTP_Response = $HTTP_Request.GetResponse()
$HTTP_Status = [int]$HTTP_Response.StatusCode
If ($HTTP_Status -eq 200)
{
$hostedVersion = "4.$($major).$($minor)"
$hostedVersions += $hostedVersion
$hostedVersionUrls += "https://$($targetAddress)/download/purestorage-vsphere-plugin.zip?version=4.$($major).$($minor)"
$identifiedArrays += $targetAddress
break
}
}
catch {}
}
}
if ($null -eq $hostedVersion)
{
for ($major=1; $major -le 1; $major++)
{
if ($null -ne $hostedVersion)
{
break
}
for ($minor=0; $minor -le 4; $minor++)
{
$HTTP_Request = [System.Net.WebRequest]::Create("https://$($targetAddress)/download/purestorage-vsphere-plugin.zip?version=3.$($major).$($minor)")
try {
$HTTP_Response = $null
$HTTP_Request.Timeout = 500
$HTTP_Response = $HTTP_Request.GetResponse()
$HTTP_Status = [int]$HTTP_Response.StatusCode
If ($HTTP_Status -eq 200)
{
$hostedVersion = "3.$($major).$($minor)"
$hostedVersions += $hostedVersion
$hostedVersionUrls += "https://$($targetAddress)/download/purestorage-vsphere-plugin.zip?version=3.$($major).$($minor)"
$identifiedArrays += $targetAddress
break
}
}
catch {}
}
}
}
}
else
{
$HTTP_Request = [System.Net.WebRequest]::Create("https://$($targetAddress)/download/purestorage-vsphere-plugin.zip?version=$($version)")
try {
$HTTP_Response = $null
$HTTP_Request.Timeout = 3000
$HTTP_Response = $HTTP_Request.GetResponse()
$HTTP_Status = [int]$HTTP_Response.StatusCode
If ($HTTP_Status -eq 200)
{
$hostedVersion = $version
$hostedVersions += $hostedVersion
$hostedVersionUrls += "https://$($targetAddress)/download/purestorage-vsphere-plugin.zip?version=$($version)"
$identifiedArrays += $targetAddress
}
}
catch {
if ($_.Exception.InnerException -like "*The operation has timed out*")
{
throw "Version checking on the FlashArray $($targetAddress) has failed due to a timeout. Closing PowerShell and re-running should fix this issue."
}
}
}
}
$plugins =@()
$arrays = 0
foreach ($plugin in $hostedVersions)
{
$Result = $null
$Result = "" | Select-Object Source,Type,Version,URL
$Result.Source = $identifiedArrays[$arrays]
$Result.Version = $plugin
$Result.URL = $hostedVersionUrls[$arrays]
if ($plugin.split(".")[0] -ge 4)
{
$Result.Type = "HTML-5"
}
else {
$Result.Type = "Flash"
}
$arrays++
$plugins += $Result
}
if ($skipPure1 -ne $true)
{
try {
$flashS3tag = Invoke-RestMethod -Method GET -Uri "https://pure-vmware-plugin-repository.s3-us-west-1.amazonaws.com/vsphere/Flex/purestorage-vsphere-plugin.zip?tagging"
$Result = $null
$Result = "" | Select-Object Source,Type,Version,URL
$Result.Source = "Pure1"
$Result.Version = $flashS3tag.Tagging.TagSet.Tag.Value
$Result.Type = "Flash"
$Result.URL = "https://pure-vmware-plugin-repository.s3-us-west-1.amazonaws.com/vsphere/Flex/purestorage-vsphere-plugin.zip"
$plugins += $Result
if ($previous -eq $true)
{
$previousVersions = (Invoke-RestMethod -Method GET -Uri "https://pure-vmware-plugin-repository.s3-us-west-1.amazonaws.com/vsphere/FlexOlderRevs/versions.txt?tagging").Tagging.TagSet.Tag.value.split(" ")
foreach ($previousVersion in $previousVersions)
{
$flashS3tag = Invoke-RestMethod -Method GET -Uri "https://pure-vmware-plugin-repository.s3-us-west-1.amazonaws.com/vsphere/FlexOlderRevs/$($previousVersion)/purestorage-vsphere-plugin.zip?tagging"
$Result = $null
$Result = "" | Select-Object Source,Type,Version,URL
$Result.Source = "Pure1"
$Result.Version = $flashS3tag.Tagging.TagSet.Tag.Value
$Result.Type = "Flash"
$Result.URL = "https://pure-vmware-plugin-repository.s3-us-west-1.amazonaws.com/vsphere/FlexOlderRevs/$($previousVersion)/purestorage-vsphere-plugin.zip"
$plugins += $Result
}
}
$htmlS3tag = Invoke-RestMethod -Method GET -Uri "https://pure-vmware-plugin-repository.s3-us-west-1.amazonaws.com/vsphere/HTML5/purestorage-vsphere-plugin.zip?tagging"
$Result = $null
$Result = "" | Select-Object Source,Type,Version,URL
$Result.Source = "Pure1"
$Result.Version = $htmlS3tag.Tagging.TagSet.Tag.Value
$Result.Type = "HTML-5"
$Result.URL = "https://pure-vmware-plugin-repository.s3-us-west-1.amazonaws.com/vsphere/HTML5/purestorage-vsphere-plugin.zip"
$plugins += $Result
if ($previous -eq $true)
{
$previousVersions = (Invoke-RestMethod -Method GET -Uri "https://pure-vmware-plugin-repository.s3-us-west-1.amazonaws.com/vsphere/HTML5OlderRevs/versions.txt?tagging").Tagging.TagSet.Tag.value.split(" ")
foreach ($previousVersion in $previousVersions)
{
$htmlS3tag = Invoke-RestMethod -Method GET -Uri "https://pure-vmware-plugin-repository.s3-us-west-1.amazonaws.com/vsphere/HTML5OlderRevs/$($previousVersion)/purestorage-vsphere-plugin.zip?tagging"
$Result = $null
$Result = "" | Select-Object Source,Type,Version,URL
$Result.Source = "Pure1"
$Result.Version = $htmlS3tag.Tagging.TagSet.Tag.Value
$Result.Type = "HTML-5"
$Result.URL = "https://pure-vmware-plugin-repository.s3-us-west-1.amazonaws.com/vsphere/HTML5OlderRevs/$($previousVersion)/purestorage-vsphere-plugin.zip"
$plugins += $Result
}
}
}
catch {}
}
if (($html -eq $True) -and ($flash -eq $false))
{
$plugins = $plugins |Where-Object {$_.Type -eq "HTML-5"}
}
elseif (($html -eq $false) -and ($flash -eq $true))
{
$plugins = $plugins |Where-Object {$_.Type -eq "Flash"}
}
if ($version -ne "")
{
$plugins = $plugins |Where-Object {$_.Version -eq $version}
}
if ($plugins.count -eq 0)
{
throw "The specified plugin version/type was not found on any of the available sources."
}
if ($global:pfavSpherePluginurl -eq $True)
{
return $plugins
}
else {
return $plugins |Select-Object Source,Type,Version
}
}
function Uninstall-PfavSpherePlugin {
<#
.SYNOPSIS
Uninstall the Pure Storage FlashArray vSphere Plugin
.DESCRIPTION
Uninstall the Flash or HTML Pure Storage FlashArray vSphere Plugin from the connected vCenter
.INPUTS
HTML or Flash
.OUTPUTS
No output unless there is an error.
.EXAMPLE
PS C:\ Uninstall-PfavSpherePlugin
Uninstalls whichever plugin is currently installed on the connected vCenter.
.EXAMPLE
PS C:\ Uninstall-PfavSpherePlugin -Confirm:$false
Uninstalls whichever plugin is currently installed on the connected vCenter with no confirmation prompt.
.EXAMPLE
PS C:\ Uninstall-PfavSpherePlugin -html
Uninstalls the HTML-5-based plugin from a vCenter.
.EXAMPLE
PS C:\ Uninstall-PfavSpherePlugin -flash
Uninstalls the flash-based plugin from a vCenter.
.NOTES
Version: 1.0
Author: Cody Hosterman https://codyhosterman.com
Creation Date: 01/03/2020
Purpose/Change: New cmdlet
*******Disclaimer:******************************************************
This scripts are offered "as is" with no warranty. While this
scripts is tested and working in my environment, it is recommended that you test
this script in a test lab before using in a production environment. Everyone can
use the scripts/commands provided here without any written permission but I
will not be liable for any damage or loss to the system.
************************************************************************
#>
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='High',DefaultParameterSetName='HTML')]
Param(
[Parameter(ParameterSetName='HTML',Position=0)]
[switch]$html,
[Parameter(ParameterSetName='Flash',Position=0)]
[switch]$flash,
[Parameter(ParameterSetName='HTML',Position=1)]
[Parameter(ParameterSetName='Flash',Position=1)]
[switch]$PreserveAuthentication
)
$ErrorActionPreference = "stop"
#gather extension manager
$services = Get-view 'ServiceInstance'
$extensionMgr = Get-view $services.Content.ExtensionManager
$htmlPluginVersion = ($extensionMgr.FindExtension("com.purestorage.purestoragehtml")).version
$flashPluginVersion = ($extensionMgr.FindExtension("com.purestorage.plugin.vsphere")).version
if (($html -ne $true) -and ($flash -ne $true))
{
if (($null -ne $flashPluginVersion) -and ($null -ne $htmlPluginVersion))
{
throw "Both the Flash and HTML-5 Plugins are installed in vCenter $($global:DefaultVIServer.name). Please specify which plugin to uninstall with the -html or -flash parameter."
}
elseif ($null -ne $flashPluginVersion) {
$flash = $true
}
elseif ($null -ne $htmlPluginVersion) {
$html = $true
}
else {
throw "There is no Pure Storage plugin installed on vCenter $($global:DefaultVIServer.name)"
}
}
#find what plugins are installed and their version
if ($html -eq $true)
{
if ($null -eq $htmlPluginVersion)
{
throw "The HTML-5 plugin is not currently installed in vCenter $($global:DefaultVIServer.name)."
}
$confirmText = "Uninstall HTML-5 plugin version $($htmlPluginVersion) on vCenter $($global:DefaultVIServer.name)?"
if ($PSCmdlet.ShouldProcess("","$($confirmText)`n`r","Please confirm uninstall.`n`r"))
{
extensionMgr.UnregisterExtension("com.purestorage.purestoragehtml")
if ($PreserveAuthentication -eq $true) {
Write-Host "Preserving Authentication Attributes"
}
else {
#Remove Custom Attribute Keys
Write-Host "Removing Authentication Attributes"
$customAttributes = Get-CustomAttribute Pure*
foreach ($attribute in $customAttributes) {
if ($attribute.Name -like "Pure1Count") {
Remove-CustomAttribute $attribute.Name -Confirm:$false
}
elseif ($attribute.Name -like "Pure1Key0") {
Remove-CustomAttribute $attribute.Name -Confirm:$false
}
elseif ($attribute.Name -like "Pure1Count") {
Remove-CustomAttribute $attribute.Name -Confirm:$false
}
elseif ($attribute.Name -like "Pure Flash Array Key Count") {
$fl = get-folder
$PureFlashArrayKeyCount = (Get-Annotation -CustomAttribute "Pure Flash Array Key Count" -Entity ($fl[0].Name)).value
foreach ($Key in 1..$PureFlashArrayKeyCount) {
Get-CustomAttribute -Name "Pure Flash Array Key[$($key - 1)]" | Remove-CustomAttribute -Confirm:$false
}
Remove-CustomAttribute $attribute.Name -Confirm:$false
}
}
}
write-host "Pure Storage HTML-5 plugin has been uninstalled."
}
}
else {
if ($null -eq $flashPluginVersion)
{
throw "The flash plugin is not currently installed in vCenter $($global:DefaultVIServer.name)."
}
$confirmText = "Uninstall flash plugin version $($flashPluginVersion) on vCenter $($global:DefaultVIServer.name)?"
if ($PSCmdlet.ShouldProcess("","$($confirmText)`n`r","Please confirm uninstall.`n`r"))
{
$extensionMgr.UnregisterExtension("com.purestorage.plugin.vsphere")
if ($PreserveAuthentication -eq $true) {
Write-Host "Preserving Authentication Attributes"
}
else {
#Remove Custom Attribute Keys
Write-Host "Removing Authentication Attributes"
$customAttributes = Get-CustomAttribute Pure*
foreach ($attribute in $customAttributes) {
if ($attribute.Name -like "Pure1Count") {
Remove-CustomAttribute $attribute.Name -Confirm:$false
}
elseif ($attribute.Name -like "Pure1Key0") {
Remove-CustomAttribute $attribute.Name -Confirm:$false
}
elseif ($attribute.Name -like "Pure1Count") {
Remove-CustomAttribute $attribute.Name -Confirm:$false
}
elseif ($attribute.Name -like "Pure Flash Array Key Count") {
$fl = get-folder
$PureFlashArrayKeyCount = (Get-Annotation -CustomAttribute "Pure Flash Array Key Count" -Entity ($fl[0].Name)).value
foreach ($Key in 1..$PureFlashArrayKeyCount) {
Get-CustomAttribute -Name "Pure Flash Array Key[$($key - 1)]" | Remove-CustomAttribute -Confirm:$false
}
Remove-CustomAttribute $attribute.Name -Confirm:$false
}
}
}
write-host "Pure Storage flash plugin has been uninstalled."
}
}
}
function Deploy-PfaAppliance {
<#
.SYNOPSIS
Deploys the Pure Storage OVA for off-array integrations and applications.
.DESCRIPTION
Deploys the Pure Storage OVA for off-array integrations and applications.
.INPUTS
An authorization key, DHCP info, IP info.
.OUTPUTS
Returns the Pure Storage Collector Object.
.EXAMPLE
PS C:\ $ds = get-datastore <datastore name>
PS C:\ $esxi = Get-VMHost <ESXi host name>
PS C:\ $pg = (Get-VirtualPortGroup -vmhost $esxi)[0]
PS C:\ $vmname = <desired name of appliance VM>
PS C:\ $authKey = <collector key from Pure1>
PS C:\ $mycreds = get-credential
PS C:\ Deploy-PfaAppliance -vmName $vmName -authorizationKey $authkey -datastore $ds -portGroup $pg -vmHost $esxi -dhcp -ovaPassword $mycreds.Password
Deploys a new OVA with DHCP network configuration. This will also change the default password to the supplied password.
.EXAMPLE
PS C:\ $ds = get-datastore <datastore name>
PS C:\ $esxi = Get-VMHost <ESXi host name>
PS C:\ $pg = (Get-VirtualPortGroup -vmhost $esxi)[0]
PS C:\ $vmname = <desired name of appliance VM>
PS C:\ $authKey = <collector key from Pure1>
PS C:\ Deploy-PfaAppliance -vmName $vmName -authorizationKey $authkey -datastore $ds -portGroup $pg -vmHost $esxi -dhcp
Deploys a new OVA with DHCP network configuration. This will leave the default password as is. You must change it manually before using the collector.
.EXAMPLE
PS C:\ $ds = get-datastore <datastore name>
PS C:\ $esxi = Get-VMHost <ESXi host name>
PS C:\ $pg = (Get-VirtualPortGroup -vmhost $esxi)[0]
PS C:\ $vmname = <desired name of appliance VM>
PS C:\ $authKey = <collector key from Pure1>
PS C:\ $mycreds = get-credential
PS C:\ Deploy-PfaAppliance -vmName $vmName -authorizationKey $authkey -datastore $ds -portGroup $pg -vmHost $esxi -ovaPassword $mycreds.Password -ipaddress <IP> -netmask <netmask> -gateway <gateway> -dnsprimary <DNS> -hostname <FQDN>
Deploys a new OVA with static network configuration. This will also change the default password to the supplied password.
.NOTES
Version: 2.0
Author: Cody Hosterman https://codyhosterman.com
Creation Date: 11/26/2019
Purpose/Change: New cmdlet
*******Disclaimer:******************************************************
This scripts are offered "as is" with no warranty. While this
scripts is tested and working in my environment, it is recommended that you test
this script in a test lab before using in a production environment. Everyone can
use the scripts/commands provided here without any written permission but I
will not be liable for any damage or loss to the system.
************************************************************************
#>
[CmdletBinding()]
Param(
[Parameter(Position=0,mandatory=$true)]
[string]$vmName,
[Parameter(ParameterSetName='StaticHost',Position=1,ValueFromPipeline=$True,mandatory=$true)]
[Parameter(ParameterSetName='DHCPHost',Position=1,ValueFromPipeline=$True,mandatory=$true)]
[VMware.VimAutomation.ViCore.Types.V1.Inventory.VMHost]$vmHost,
[Parameter(Position=2,mandatory=$true)]
[VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.Datastore]$datastore,
[Parameter(Position=3,mandatory=$true)]
[VMware.VimAutomation.ViCore.Types.V1.Host.Networking.VirtualPortGroupBase]$portGroup,
[Parameter(ParameterSetName='StaticCluster',Position=4,mandatory=$true,ValueFromPipeline=$True)]
[Parameter(ParameterSetName='DHCPCluster',Position=4,mandatory=$true,ValueFromPipeline=$True)]
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Cluster]$cluster,
[Parameter(ParameterSetName='DHCPCluster',Position=5)]
[Parameter(ParameterSetName='DHCPHost',Position=5)]
[switch]$dhcp,
[Parameter(Position=6,mandatory=$true)]
[string]$authorizationKey,
[Parameter(ParameterSetName='StaticCluster',Position=7,mandatory=$true)]
[Parameter(ParameterSetName='StaticHost',Position=7,mandatory=$true)]
[string]$ipAddress,
[Parameter(ParameterSetName='StaticCluster',Position=8,mandatory=$true)]
[Parameter(ParameterSetName='StaticHost',Position=8,mandatory=$true)]
[string]$netmask,
[Parameter(ParameterSetName='StaticCluster',Position=9,mandatory=$true)]
[Parameter(ParameterSetName='StaticHost',Position=9,mandatory=$true)]
[string]$gateway,
[Parameter(ParameterSetName='StaticCluster',Position=10,mandatory=$true)]
[Parameter(ParameterSetName='StaticHost',Position=10,mandatory=$true)]
[string]$dnsPrimary,
[Parameter(ParameterSetName='StaticCluster',Position=11,mandatory=$true)]
[Parameter(ParameterSetName='StaticHost',Position=11,mandatory=$true)]
[string]$dnsSecondary,
[Parameter(ParameterSetName='StaticCluster',Position=12,mandatory=$true)]
[Parameter(ParameterSetName='StaticHost',Position=12,mandatory=$true)]
[string]$hostName,
[Parameter(Position=13)]
[string]$ovaLocation,
[Parameter(Position=14)]
[SecureString]$ovaPassword,
[Parameter(Position=15)]
[int32]$passwordChangeWait = 60,
[Parameter(Position=16)]
[switch]$silent
)
$ErrorActionPreference = "stop"
$vCenterVersion = $Global:DefaultVIServer | Select-Object Version
if (($vCenterVersion.Version -eq "6.0.0") -and ($ovaPassword.length -ge 1))
{
Throw "vCenter version 6.0 does not support the APIs that are required to change the default password. Please re-run the deployment without specifying a password. You will then need to manually SSH in or use the VM console to change the default password to one of your own."
}
try
{
$foundVM = get-vm $vmName
}
catch {}
if ($null -ne $foundVM)
{
throw "A VM with the name $($vmName) already exists. Please specify a unique name."
}
if ($null -eq $vmhost)
{
$vmHost = $cluster | get-vmhost | where-object {($_.version -like '5.5.*') -or ($_.version -like '6.*')}| where-object {($_.ConnectionState -eq 'Connected')} |Select-Object -last 1
}
if (($null -eq $ovaLocation)-or ($ovaLocation -eq ""))
{
if ($silent -ne $true)
{
write-host ""
write-host "Downloading OVA to $($env:temp)\purestorage-vma-collector_latest-signed.ova..."
}
$ProgressPreference = 'SilentlyContinue'
if ([System.IO.File]::Exists($ovaLocation))
{
throw "There is already an OVA at the default location. Ensure file at $($ovaLocation) is correct and directly specify it or delete it so it can be re-downloaded with the latest version."
}
Invoke-WebRequest -Uri "https://static.pure1.purestorage.com/vm-analytics-collector/purestorage-vma-collector_latest-signed.ova" -OutFile $env:temp\purestorage-vma-collector_latest-signed.ova
$ovaLocation = "$($env:temp)\purestorage-vma-collector_latest-signed.ova"
$deleteOVA = $true
if ($silent -ne $true)
{
write-host "Download complete."
}
}
else {
$deleteOVA = $false
if (![System.IO.File]::Exists($ovaLocation))
{
throw "Could not find OVA file. Ensure file location $($ovaLocation) is correct/accessible."
}
}
try
{
$ovaConfig = Get-OvfConfiguration $ovaLocation
if ($dhcp -eq $true)
{
$ovaConfig.Common.DHCP.value = $true
}
else
{
$ovaConfig.Common.IP_Address.value = $ipAddress
$ovaConfig.Common.Netmask.value = $netmask
$ovaConfig.Common.Gateway.value = $gateway
$ovaConfig.Common.DNS_Server_1.value = $dnsPrimary
$ovaConfig.Common.DNS_Server_2.value = $dnsSecondary
$ovaConfig.Common.Hostname.value = $hostName
$ovaConfig.Common.DHCP.value = $false
}
$ovaConfig.Common.Authorization_Key.value = $authorizationKey
$ovaConfig.NetworkMapping.VM_Network.value = $portGroup
if ($silent -ne $true)
{
write-host "Deploying OVA..."
}
$vm = Import-VApp -Source $ovaLocation -OvfConfiguration $ovaConfig -Name $vmName -VMHost $vmhost -Datastore $datastore -DiskStorageFormat thin -Force
if ($silent -ne $true)
{
write-host "OVA deployed."
}
}
catch
{
if ($deleteOVA -eq $true)
{
Remove-Item $ovaLocation
}
throw $Global:Error[0]
}
if ($deleteOVA -eq $true)
{
Remove-Item $ovaLocation
}
if ($silent -ne $true)
{
write-host "Powering-on VM..."
}
Start-VM $vm |out-null
if ($ovaPassword.length -ge 1)
{
if ($silent -ne $true)