This repository has been 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
/
Copy pathRemove-PfaRestSession.ps1
63 lines (59 loc) · 2.46 KB
/
Remove-PfaRestSession.ps1
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
#region Remove-PfaRestSession
<#
.SYNOPSIS
Disconnects a FlashArray REST session
.DESCRIPTION
Takes in a FlashArray Connection or session and disconnects on the FlashArray.
.INPUTS
FlashArray connection or session
.OUTPUTS
Returns success or failure.
.NOTES
Version: 2.0
Author: Cody Hosterman https://codyhosterman.com
Creation Date: 08/24/2020
Purpose/Change: Core support
.EXAMPLE
PS C:\ $restSession | Remove-PfaRestSession -flasharray $fa
Disconnects a direct REST session to a FlashArray. Does not disconnect the PowerShell session.
*******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, mandatory = $true)]
[Microsoft.PowerShell.Commands.WebRequestSession]$FaSession,
[Parameter(Position = 1, ValueFromPipeline = $True, mandatory = $true)]
[PurePowerShell.PureArray]$Flasharray
)
if ($null -eq $flasharray) {
$flasharray = checkDefaultFlashArray
}
$purevip = $flasharray.endpoint
$apiVersion = $flasharray.ApiVersion
#Delete FA session
if ($PSVersionTable.PSEdition -ne "Core") {
Add-Type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class IDontCarePolicy : ICertificatePolicy {
public IDontCarePolicy() {}
public bool CheckValidationResult(
ServicePoint sPoint, X509Certificate cert,
WebRequest wRequest, int certProb) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object IDontCarePolicy
Invoke-RestMethod -Method Delete -Uri "https://${purevip}/api/${apiVersion}/auth/session" -WebSession $faSession -ErrorAction Stop | Out-Null
}
else {
Invoke-RestMethod -Method Delete -Uri "https://${purevip}/api/${apiVersion}/auth/session" -WebSession $faSession -ErrorAction Stop -SkipCertificateCheck | Out-Null
}
#endregion