-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-HCAUser.ps1
48 lines (41 loc) · 1.72 KB
/
Get-HCAUser.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
function Get-HCAUser {
[CmdletBinding()]
[OutputType([PSCustomObject])]
param(
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[string] $UserUrl,
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[Microsoft.PowerShell.Commands.WebRequestSession] $WebSession,
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[string] $JWTToken
)
begin { }
process {
$Body = @{
JWT = $JWTToken
LANG = "en-US"
} | ConvertTo-Json -Depth 2
$RequestParameters = @{
Uri = $UserUrl
Method = 'Post'
WebSession = $WebSession
Body = $Body
ContentType = 'application/json'
Headers = @{
"Accept" = "application/json"
"Sec-Fetch-Site" = "same-origin"
"Sec-Fetch-Mode" = "navigate"
"Sec-Fetch-Dest" = "document"
"User-Agent" = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246"
}
}
$Request = Invoke-RestMethod @RequestParameters -ErrorAction Stop -SkipCertificateCheck
# Verify if the user only has one contract. In that case we output the values right away to the output object:
$ReturnObject = New-Object System.Object
$ReturnObject | Add-Member -Type NoteProperty -Name WebSession -Value $WebSession
$ReturnObject | Add-Member -Type NoteProperty -Name JWTToken -Value $JWTToken
$ReturnObject | Add-Member -Type NoteProperty -Name User -Value $Request
$ReturnObject
}
end { }
}