-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRemove-DCNMAuthToken.ps1
52 lines (50 loc) · 1.69 KB
/
Remove-DCNMAuthToken.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
function Remove-DCNMAuthToken {
<#
.SYNOPSIS
Logs out of the DCNM API
.DESCRIPTION
This cmdlet will invoke a REST post against the DCNM API, that will destroy the AuthToken generated
from the New-DCNMAuthentication function, and log the user out
.EXAMPLE
Remove-DCNMAuthToken
.PARAMETER dcnmHost
Base URL of DCNM
.PARAMETER token
Dcnm-Token value
/#>
param
(
[Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true)]
[string]$DCNMHost=$Global:DCNMHost,
[Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true)]
[string]$token=$Global:DCNMAuthToken
)
Begin {
if ($PSEdition -eq 'Core') {$IsCore=$true} else {
$IsCore=$false
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;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
[System.Net.ServicePointManager]::SecurityProtocol = 'Tls12'
}
}
Process {
$uri = "$DCNMHost/rest/logout"
$headers = @{ 'Dcnm-Token' = "$env:DCNMAuthToken" ; 'Content-Type' = 'application/json' ; Accept = 'application/json' }
if ($IsCore -eq $true) {
$AuthResponse = Invoke-WebRequest -SkipCertificateCheck -Uri $uri -Headers $headers -Method Post
} else {$AuthResponse = Invoke-WebRequest -Uri $uri -Headers $headers -Method Post -Body
}
$AuthResponse
}
End {Remove-Variable -Name DCNM* -Scope Global}
}