forked from gildas/posh-ic
-
Notifications
You must be signed in to change notification settings - Fork 2
/
New-ICSchedule.ps1
83 lines (69 loc) · 2.48 KB
/
New-ICSchedule.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
<#
# AUTHOR : Paul McGurn
# TODO: Allow for more precision on date/time/recurrence settings
#>
function New-ICSchedule()
{
<#
.SYNOPSIS
Creates a new IC schedule
.DESCRIPTION
Creates a new IC schedule
.PARAMETER ICSession
The Interaction Center Session
.PARAMETER ICschedule
The Interaction Center schedule
.PARAMETER Description
[Optional] Description for the schedule.
.PARAMETER isActive
[Optional] Whether the schedule is active. Defaults to false.
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)] [Alias("Session", "Id")] $ICSession,
[Parameter(Mandatory=$true)] [Alias("Schedule")] [string] $ICSchedule,
[Parameter(Mandatory=$false)] [string] $Description="",
[Parameter(Mandatory=$false)] [System.Boolean] $isActive=$false
)
$scheduleExists = Get-ICSchedule $ICSession -ICSchedule $ICSchedule
if (-not ([string]::IsNullOrEmpty($scheduleExists))) {
Write-Verbose "Schedule already exists, returning existing copy"
return $scheduleExists
}
$headers = @{
"Accept-Language" = $ICSession.language;
"ININ-ICWS-CSRF-Token" = $ICSession.token;
}
$configurationId = New-ICConfigurationId $ICSchedule
#Add URI and Description to base configuration ID
$configurationId.Add("displayName", $ICSchedule)
$configurationId.Add("uri", "/configuration/schedules/" + [System.Web.HttpUtility]::UrlEncode($ICSchedule))
$recurrenceId = New-ICConfigurationId $ICSchedule
$recurrenceId.Add("displayName",$ICSchedule + "Recurrence1")
$recurrenceId.Add("uri", "/configuration/schedules/" + [System.Web.HttpUtility]::UrlEncode($ICSchedule + "Recurrence1"))
$recurrenceHash = [PSCustomObject]@{
"configurationId" = $recurrenceId
"endDate" = "2019-01-02"
"endTime" = "00:00:00"
"patternType" = 0
"startDate" = "2019-01-01"
"startTime" = "00:00:00"
"isDaySpan" = $false
"isRelative" = $false
"month" = 0
"weeklyEndTime" = "00:00:00"
"weeklyStartTime" = "00:00:00"
"isAllDay" = $true
}
$scheduleRecurrences = [System.Collections.ArrayList]@()
$scheduleRecurrences.Add($recurrenceHash);
$body = ConvertTo-Json([PSCustomObject]@{
"configurationId" = $configurationId
"isActive" = $isActive
"Description" = $Description
"scheduleRecurrences" = $scheduleRecurrences
}) -Depth 5
Write-Verbose $body
$response = Invoke-RestMethod -Uri "$($ICsession.baseURL)/$($ICSession.id)/configuration/schedules" -Body $body -Method Post -Headers $headers -WebSession $ICSession.webSession -ErrorAction Stop
return $response
}