forked from gildas/posh-ic
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Get-ICSessionStatus.ps1
53 lines (50 loc) · 1.41 KB
/
Get-ICSessionStatus.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
<#
# AUTHOR : Gildas Cherruel
#>
function Get-ICSessionStatus() # {{{2
{
# Documentation {{{3
<#
.SYNOPSIS
Gets the status of an ICSession
.DESCRIPTION
Gets the status of an ICSession
.PARAMETER ICSession
The Interaction Center Session
#> # }}}3
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[Alias("Session", "Id")]
[ININ.ICSession] $ICSession
)
$headers = @{
"Accept-Language" = $ICSession.language;
"ININ-ICWS-CSRF-Token" = $ICSession.token;
}
try
{
$response = Invoke-RestMethod -Uri "$($ICsession.baseURL)/$($ICSession.id)/connection" -Method Get -Headers $headers -WebSession $ICSession.webSession -ErrorAction Stop
Write-Verbose "Response: $response"
[ININ.ConnectionState] $response.connectionState
}
catch [System.Net.WebException]
{
if ($_.Exception.Response.StatusCode -eq 'Unauthorized')
{
$details = $_.ErrorDetails | ConvertFrom-Json
if ( `
(($details.errorId -eq 'error.request.connection.authenticationFailure') -and `
($details.errorCode -eq -2147221499)) ` <# Session Identifier is invalid #> `
-or `
($details.errorCode -eq 1) <# Session Identifier is wrong format #> `
-or `
($details.errorCode -eq 2) <# Session Identifier was not found #> `
)
{
return [ININ.ConnectionState]::Down
}
}
Throw $_
}
} # }}}2