forked from gildas/posh-ic
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Set-ICLicense.ps1
108 lines (95 loc) · 3.45 KB
/
Set-ICLicense.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<#
# AUTHOR : Pierrick Lozach
#>
function Set-ICLicense() # {{{2
{
# Documentation {{{3
<#
.SYNOPSIS
Assigns a CIC license to a user
.DESCRIPTION
Assigns a CIC license to a specific CIC user.
.PARAMETER ICSession
The Interaction Center Session
.PARAMETER ICUser
The Interaction Center User Identifier
.PARAMETER HasClientAccess
If true, user is allowed to access the Interaction Client or Desktop applications. Default value is true.
.PARAMETER LicenseActive
If true, assigned licenses should be considered active by the server. Default value is true.
.PARAMETER MediaLevel
Used to configure how many interaction types an ACD user can handle at a specified time. Set to 0 for None, 1, 2 or 3. Default value is 3.
.PARAMETER AdditionalLicenses
List of additional licenses to assign to the user.
#> # }}}3
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)] [Alias("Session", "Id")] [ININ.ICSession] $ICSession,
[Parameter(Mandatory=$true)] [Alias("User")] [string] $ICUser,
[Parameter(Mandatory=$false)] [Alias("ClientAccess")] [boolean] $HasClientAccess,
[Parameter(Mandatory=$false)] [Alias("EnableLicenses", "ActivateLicenses")] [boolean] $LicenseActive,
[Parameter(Mandatory=$false)] [Alias("MediaLicense")] [int] $MediaLevel,
[Parameter(Mandatory=$false)] [string[]] $AdditionalLicenses
)
$userExists = Get-ICUser $ICSession -ICUser $ICUser
if ([string]::IsNullOrEmpty($userExists)) {
return
}
if (!$PSBoundParameters.ContainsKey('HasClientAccess'))
{
$HasClientAccess = $true
}
if (!$PSBoundParameters.ContainsKey('LicenseActive'))
{
$LicenseActive = $true
}
if (!$PSBoundParameters.ContainsKey('MediaLevel'))
{
$MediaLevel = 3
}
# Add headers
$headers = @{
"Accept-Language" = $ICSession.language;
"ININ-ICWS-CSRF-Token" = $ICSession.token;
}
# Build base body
$body = @{
"configurationId" = New-ICConfigurationId $ICUser
"extension" = $Extension
}
############
# Licenses #
############
$licenseProperties = @{
"hasClientAccess" = $HasClientAccess
"licenseActive" = $LicenseActive
"mediaLevel" = $MediaLevel
}
# Add Additional Licenses if there are any
if ($AdditionalLicenses) {
# Add all licenses?
if ($AdditionalLicenses.Length -eq 1 -and $AdditionalLicenses[0] -eq "*") {
$allAdditionalLicenses = ((Get-ICLicenseAllocations $ICSession).items | foreach { if (-not ($_.configurationId.id -match "EASYSCRIPTER" -or $_.configurationId.id -match "MSCRM")) { $_.configurationId } })
# Add missing licenses
$allAdditionalLicenses += New-ICConfigurationId "I3_ACCESS_IPAD_USER_SUPERVISOR"
$allAdditionalLicenses += New-ICConfigurationId "I3_OPTIMIZER_SHOWRTA"
$allAdditionalLicenses += New-ICConfigurationId "I3_OPTIMIZER_SCHEDULABLE"
$licenseProperties.Add("additionalLicenses", $allAdditionalLicenses)
}
else {
$licenseProperties += @{
"additionalLicenses" = @( $AdditionalLicenses | foreach { New-ICConfigurationId $_ } )
}
}
}
if (![string]::IsNullOrEmpty($licenseProperties)) {
$body += @{
"licenseProperties" = $licenseProperties
}
}
$body = ConvertTo-Json($body) -Depth 4
# Call it!
$response = Invoke-RestMethod -Uri "$($ICsession.baseURL)/$($ICSession.id)/configuration/users/$($ICUser)" -Body $body -Method Put -Headers $headers -WebSession $ICSession.webSession -ErrorAction Stop
Write-Output $response | Format-Table
[PSCustomObject] $response
} # }}}2