This repository was archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathNew-PfaRestSession.ps1
More file actions
86 lines (84 loc) · 3.29 KB
/
New-PfaRestSession.ps1
File metadata and controls
86 lines (84 loc) · 3.29 KB
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
#region New-PfaRestSession
<#
.SYNOPSIS
Connects to FlashArray and creates a REST connection.
.DESCRIPTION
For operations that are in the FlashArray REST, but not in the Pure Storage PowerShell SDK yet, this provides a connection for invoke-restmethod to use.
.INPUTS
FlashArray connection or FlashArray IP/FQDN and credentials
.OUTPUTS
Returns REST session
.NOTES
Version: 2.0
Author: Cody Hosterman https://codyhosterman.com
Creation Date: 08/24/2020
Purpose/Change: Core support
.EXAMPLE
PS C:\ $faCreds = get-credential
PS C:\ $fa = New-PfaConnection -endpoint flasharray-m20-2 -credentials $faCreds -defaultArray
PS C:\ $restSession = New-PfaRestSession -flasharray $fa
Creates a direct REST session to the FlashArray for REST operations that are not supported by the PowerShell SDK yet. Returns it and also stores it in $global:faRestSession
*******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,ValueFromPipeline=$True)]
[PurePowerShell.PureArray]$Flasharray
)
#Connect to FlashArray
if ($null -eq $flasharray)
{
$flasharray = checkDefaultFlashArray
}
if ($PSEdition -ne 'Core'){
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
#Create FA REST session
$SessionAction = @{
api_token = $flasharray.ApiToken
}
Invoke-RestMethod -Method Post -Uri "https://$($flasharray.Endpoint)/api/$($flasharray.apiversion)/auth/session" -Body $SessionAction -SessionVariable Session -ErrorAction Stop |Out-Null
}
else {
$SessionAction = @{
api_token = $flasharray.ApiToken
}
Invoke-RestMethod -Method Post -Uri "https://$($flasharray.Endpoint)/api/$($flasharray.apiversion)/auth/session" -Body $SessionAction -SessionVariable Session -ErrorAction Stop -SkipCertificateCheck |Out-Null
}
$global:faRestSession = $Session
return $global:faRestSession
#endregion
<# Invoke-RestMethod
$Body = @{
snap = "true"
source = [Object[]]"$SnapshotVolume"
suffix = $SnapshotSuffix"
}
$Params = @{
Method = "Post"
Uri = "https://$($flasharray.EndPoint)/api/$(flasharray.apiversion)/volume"
Body = ($Body | ConvertTo-Json)
WebSession = $Session
ContentType = "application/json"
ErrorAction = Stop
-SkipCertificateCheck
}
Invoke-RestMethod @Params
#>